Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit b6ae1fc

Browse filesBrowse files
joyeecheungaduh95
authored andcommitted
test: split test-embedding.js and run tests in parallel
Split the tests so that it's easier to isolate and debug issues, and we can run the test cases in parallel to speed up. Also add more comments about what they are testing. PR-URL: #61571 Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
1 parent af7c927 commit b6ae1fc
Copy full SHA for b6ae1fc

16 files changed

+374-169Lines changed: 374 additions & 169 deletions
Expand file treeCollapse file tree
Open diff view settings
Collapse file
+17Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
'use strict';
2+
3+
// Tests that createRequire() works correctly with local fs in embedded environments.
4+
// The createRequire() call is in embedtest.cc.
5+
6+
const common = require('../common');
7+
const fixtures = require('../common/fixtures');
8+
const { spawnSyncAndExit } = require('../common/child_process');
9+
10+
const fixturePath = JSON.stringify(fixtures.path('exit.js'));
11+
spawnSyncAndExit(
12+
common.resolveBuiltBinary('embedtest'),
13+
[`require(${fixturePath})`, 92],
14+
{
15+
status: 92,
16+
signal: null,
17+
});
Collapse file
+15Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
'use strict';
2+
3+
// Tests that createRequire() from embedded environments still cannot access internals.
4+
// The createRequire() call is in embedtest.cc.
5+
6+
const common = require('../common');
7+
const { spawnSyncAndExit } = require('../common/child_process');
8+
9+
spawnSyncAndExit(
10+
common.resolveBuiltBinary('embedtest'),
11+
['require("lib/internal/test/binding")'],
12+
{
13+
status: 1,
14+
signal: null,
15+
});
Collapse file
+27Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
'use strict';
2+
3+
// Tests node::ProcessInitializationFlags::kDisableNodeOptionsEnv works correctly.
4+
5+
const common = require('../common');
6+
const { spawnSyncAndExit } = require('../common/child_process');
7+
const os = require('os');
8+
9+
if (process.config.variables.node_without_node_options) {
10+
common.skip('NODE_REPL_EXTERNAL_MODULE cannot be tested with --without-node-options');
11+
}
12+
13+
const embedtest = common.resolveBuiltBinary('embedtest');
14+
spawnSyncAndExit(
15+
embedtest,
16+
['require("os")'],
17+
{
18+
env: {
19+
...process.env,
20+
'NODE_REPL_EXTERNAL_MODULE': 'fs',
21+
},
22+
},
23+
{
24+
status: 9,
25+
signal: null,
26+
stderr: `${embedtest}: NODE_REPL_EXTERNAL_MODULE can't be used with kDisableNodeOptionsEnv${os.EOL}`,
27+
});
Collapse file
+14Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
'use strict';
2+
3+
// Tests that process.exitCode works correctly in embedded environments.
4+
5+
const common = require('../common');
6+
const { spawnSyncAndExit } = require('../common/child_process');
7+
8+
spawnSyncAndExit(
9+
common.resolveBuiltBinary('embedtest'),
10+
['process.exitCode = 8'],
11+
{
12+
status: 8,
13+
signal: null,
14+
});
Collapse file
+16Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
'use strict';
2+
3+
// Tests node::LoadEnvironment() with main_script_source_utf8 works.
4+
5+
const common = require('../common');
6+
const { spawnSyncAndAssert } = require('../common/child_process');
7+
8+
const embedtest = common.resolveBuiltBinary('embedtest');
9+
10+
spawnSyncAndAssert(
11+
embedtest,
12+
['console.log(42)'],
13+
{
14+
trim: true,
15+
stdout: '42',
16+
});
Collapse file
+17Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
'use strict';
2+
3+
// Test node::LoadEnvironment() works with non-ASCII source code. The variable
4+
// comes from embedtest.cc.
5+
6+
const common = require('../common');
7+
const { spawnSyncAndAssert } = require('../common/child_process');
8+
9+
const embedtest = common.resolveBuiltBinary('embedtest');
10+
11+
spawnSyncAndAssert(
12+
embedtest,
13+
['console.log(embedVars.nön_ascıı)'],
14+
{
15+
trim: true,
16+
stdout: '🏳️‍🌈',
17+
});
Collapse file
+50Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
'use strict';
2+
3+
// Tests node::EmbedderSnapshotData::FromFile() works correctly.
4+
// The snapshot is created in embedtest.cc.
5+
6+
const common = require('../common');
7+
const tmpdir = require('../common/tmpdir');
8+
const assert = require('assert');
9+
const fixtures = require('../common/fixtures');
10+
11+
const {
12+
spawnSyncAndAssert,
13+
spawnSyncAndExitWithoutError,
14+
} = require('../common/child_process');
15+
16+
const snapshotFixture = fixtures.path('snapshot', 'echo-args.js');
17+
const embedtest = common.resolveBuiltBinary('embedtest');
18+
19+
const buildSnapshotExecArgs = [
20+
`eval(require("fs").readFileSync(${JSON.stringify(snapshotFixture)}, "utf8"))`,
21+
'arg1', 'arg2',
22+
];
23+
const snapshotBlobArgs = [
24+
'--embedder-snapshot-blob', tmpdir.resolve('embedder-snapshot.blob'),
25+
];
26+
27+
const runSnapshotExecArgs = ['arg3', 'arg4'];
28+
29+
tmpdir.refresh();
30+
31+
// Build the snapshot with the --embedder-snapshot-as-file flag.
32+
spawnSyncAndExitWithoutError(
33+
embedtest,
34+
['--', ...buildSnapshotExecArgs, ...snapshotBlobArgs, '--embedder-snapshot-as-file', '--embedder-snapshot-create'],
35+
{ cwd: tmpdir.path });
36+
37+
// Run the snapshot and check the serialized and refreshed argv values.
38+
spawnSyncAndAssert(
39+
embedtest,
40+
['--', ...runSnapshotExecArgs, ...snapshotBlobArgs ],
41+
{ cwd: tmpdir.path },
42+
{
43+
stdout(output) {
44+
assert.deepStrictEqual(JSON.parse(output), {
45+
originalArgv: [embedtest, '__node_anonymous_main', ...buildSnapshotExecArgs],
46+
currentArgv: [embedtest, ...runSnapshotExecArgs],
47+
});
48+
return true;
49+
},
50+
});
Collapse file
+50Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
'use strict';
2+
3+
// Tests snapshot support in embedded environments.
4+
// See embedtest.cc for the API usage.
5+
6+
const common = require('../common');
7+
const tmpdir = require('../common/tmpdir');
8+
const assert = require('assert');
9+
const fixtures = require('../common/fixtures');
10+
11+
const {
12+
spawnSyncAndAssert,
13+
spawnSyncAndExitWithoutError,
14+
} = require('../common/child_process');
15+
16+
const snapshotFixture = fixtures.path('snapshot', 'echo-args.js');
17+
const embedtest = common.resolveBuiltBinary('embedtest');
18+
19+
const buildSnapshotExecArgs = [
20+
`eval(require("fs").readFileSync(${JSON.stringify(snapshotFixture)}, "utf8"))`,
21+
'arg1', 'arg2',
22+
];
23+
const snapshotBlobArgs = [
24+
'--embedder-snapshot-blob', tmpdir.resolve('embedder-snapshot.blob'),
25+
];
26+
27+
const runSnapshotExecArgs = ['arg3', 'arg4'];
28+
29+
tmpdir.refresh();
30+
31+
// Build the snapshot with the default flags.
32+
spawnSyncAndExitWithoutError(
33+
embedtest,
34+
['--', ...buildSnapshotExecArgs, ...snapshotBlobArgs, '--embedder-snapshot-create'],
35+
{ cwd: tmpdir.path });
36+
37+
// Run the snapshot and check the serialized and refreshed argv values.
38+
spawnSyncAndAssert(
39+
embedtest,
40+
['--', ...runSnapshotExecArgs, ...snapshotBlobArgs ],
41+
{ cwd: tmpdir.path },
42+
{
43+
stdout(output) {
44+
assert.deepStrictEqual(JSON.parse(output), {
45+
originalArgv: [embedtest, '__node_anonymous_main', ...buildSnapshotExecArgs],
46+
currentArgv: [embedtest, ...runSnapshotExecArgs],
47+
});
48+
return true;
49+
},
50+
});
Collapse file
+43Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
'use strict';
2+
3+
// Tests creating vm contexts after snapshot deserialization works
4+
// in embedded environments.
5+
6+
const common = require('../common');
7+
const tmpdir = require('../common/tmpdir');
8+
const fixtures = require('../common/fixtures');
9+
10+
const {
11+
spawnSyncAndAssert,
12+
spawnSyncAndExitWithoutError,
13+
} = require('../common/child_process');
14+
15+
const snapshotFixture = fixtures.path('snapshot', 'create-vm.js');
16+
const embedtest = common.resolveBuiltBinary('embedtest');
17+
18+
const buildSnapshotExecArgs = [
19+
`eval(require("fs").readFileSync(${JSON.stringify(snapshotFixture)}, "utf8"))`,
20+
'arg1', 'arg2',
21+
];
22+
const snapshotBlobArgs = [
23+
'--embedder-snapshot-blob', tmpdir.resolve('embedder-snapshot.blob'),
24+
];
25+
26+
const runSnapshotExecArgs = ['arg3', 'arg4'];
27+
28+
tmpdir.refresh();
29+
30+
// Build the snapshot with the vm-creating code in serialized main funciton.
31+
spawnSyncAndExitWithoutError(
32+
embedtest,
33+
['--', ...buildSnapshotExecArgs, ...snapshotBlobArgs, '--embedder-snapshot-create'],
34+
{ cwd: tmpdir.path });
35+
36+
// Run the snapshot that creates a vm context from the snapshot.
37+
spawnSyncAndAssert(
38+
embedtest,
39+
['--', ...runSnapshotExecArgs, ...snapshotBlobArgs ],
40+
{ cwd: tmpdir.path },
41+
{
42+
stdout: /value: 42/,
43+
});
Collapse file
+50Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
'use strict';
2+
3+
// Tests node::SnapshotFlags::kWithoutCodeCache. See
4+
// embedtest.cc for more details.
5+
6+
const common = require('../common');
7+
const tmpdir = require('../common/tmpdir');
8+
const assert = require('assert');
9+
const fixtures = require('../common/fixtures');
10+
11+
const {
12+
spawnSyncAndAssert,
13+
spawnSyncAndExitWithoutError,
14+
} = require('../common/child_process');
15+
16+
const snapshotFixture = fixtures.path('snapshot', 'echo-args.js');
17+
const embedtest = common.resolveBuiltBinary('embedtest');
18+
19+
const buildSnapshotExecArgs = [
20+
`eval(require("fs").readFileSync(${JSON.stringify(snapshotFixture)}, "utf8"))`,
21+
'arg1', 'arg2',
22+
];
23+
const snapshotBlobArgs = [
24+
'--embedder-snapshot-blob', tmpdir.resolve('embedder-snapshot.blob'),
25+
];
26+
27+
const runSnapshotExecArgs = ['arg3', 'arg4'];
28+
29+
tmpdir.refresh();
30+
31+
// Build the snapshot with the --without-code-cache flag.
32+
spawnSyncAndExitWithoutError(
33+
embedtest,
34+
['--', ...buildSnapshotExecArgs, ...snapshotBlobArgs, '--without-code-cache', '--embedder-snapshot-create'],
35+
{ cwd: tmpdir.path });
36+
37+
// Run the snapshot and check the serialized and refreshed argv values.
38+
spawnSyncAndAssert(
39+
embedtest,
40+
['--', ...runSnapshotExecArgs, ...snapshotBlobArgs ],
41+
{ cwd: tmpdir.path },
42+
{
43+
stdout(output) {
44+
assert.deepStrictEqual(JSON.parse(output), {
45+
originalArgv: [embedtest, '__node_anonymous_main', ...buildSnapshotExecArgs],
46+
currentArgv: [embedtest, ...runSnapshotExecArgs],
47+
});
48+
return true;
49+
},
50+
});

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.