-
-
Notifications
You must be signed in to change notification settings - Fork 35.3k
Expand file tree
/
Copy pathtest-assert-snapshot-transform-project-root.js
More file actions
46 lines (34 loc) · 1.61 KB
/
test-assert-snapshot-transform-project-root.js
File metadata and controls
46 lines (34 loc) · 1.61 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
'use strict';
const common = require('../common');
const assert = require('node:assert/strict');
const path = require('node:path');
const { pathToFileURL } = require('node:url');
const snapshot = require('../common/assertSnapshot');
// Coverage: boundary strip, URL tokens, file:// root, % encoding.
{
const stripProjectRoot = snapshot.transformProjectRoot('');
const projectRoot = path.resolve(__dirname, '..', '..');
assert.strictEqual(
stripProjectRoot(`${projectRoot}${path.sep}test${path.sep}fixtures`),
`${path.sep}test${path.sep}fixtures`,
);
const shouldNotStrip = `${projectRoot}_modules`;
assert.strictEqual(stripProjectRoot(shouldNotStrip), shouldNotStrip);
const urlLike = `https://${projectRoot}js.org`;
assert.strictEqual(stripProjectRoot(urlLike), urlLike);
const shouldNotStripSuffix = `${projectRoot}suffix/test`;
assert.strictEqual(stripProjectRoot(shouldNotStripSuffix), shouldNotStripSuffix);
const fileUrl = pathToFileURL(projectRoot).href;
assert.strictEqual(stripProjectRoot(`${fileUrl}/test/fixtures`), 'file:///test/fixtures');
const fileUrlWithSpace = pathToFileURL(path.join(projectRoot, 'spaced dir')).href;
assert.strictEqual(stripProjectRoot(fileUrlWithSpace), 'file:///spaced%20dir');
if (common.isWindows) {
const projectRootPosix = projectRoot.replaceAll(path.win32.sep, path.posix.sep);
assert.strictEqual(
stripProjectRoot(`${projectRootPosix}/test/fixtures`),
'/test/fixtures',
);
const shouldNotStripPosix = `${projectRootPosix}_modules`;
assert.strictEqual(stripProjectRoot(shouldNotStripPosix), shouldNotStripPosix);
}
}