-
-
Notifications
You must be signed in to change notification settings - Fork 35.4k
Expand file tree
/
Copy pathtest-assert-snapshot-transform-project-root.js
More file actions
39 lines (30 loc) · 1.32 KB
/
test-assert-snapshot-transform-project-root.js
File metadata and controls
39 lines (30 loc) · 1.32 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
'use strict';
require('../common');
const assert = require('node:assert/strict');
const path = require('node:path');
const snapshot = require('../common/assertSnapshot');
// `transformProjectRoot()` is used by many snapshot-based tests to strip the
// project root from stack traces and other outputs. Ensure it only strips the
// project root when it is a real path prefix, not when it is part of some other
// token (e.g., "node_modules" or URLs).
{
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);
if (process.platform === 'win32') {
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);
}
}