mirror of
https://github.com/nodejs/node.git
synced 2026-10-14 10:26:26 -04:00
test: use expectSyncExit{WithErrors} in snapshot tests
..and replace the similar code added for logging. PR-URL: https://github.com/nodejs/node/pull/49020 Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
This commit is contained in:
1 parent
034c80126e
commit
a3f12e4a7e
3 files changed
+69
-87
No files matched your search
@@ -7,6 +7,7 @@ const assert = require('assert');
|
||||
const { spawnSync } = require('child_process');
|
||||
const tmpdir = require('../common/tmpdir');
|
||||
const fixtures = require('../common/fixtures');
|
||||
const { expectSyncExitWithoutError } = require('../common/child_process');
|
||||
const fs = require('fs');
|
||||
|
||||
const v8 = require('v8');
|
||||
@@ -36,11 +37,8 @@ const entry = fixtures.path('snapshot', 'v8-startup-snapshot-api.js');
|
||||
], {
|
||||
cwd: tmpdir.path
|
||||
});
|
||||
if (child.status !== 0) {
|
||||
console.log(child.stderr.toString());
|
||||
console.log(child.stdout.toString());
|
||||
assert.strictEqual(child.status, 0);
|
||||
}
|
||||
|
||||
expectSyncExitWithoutError(child);
|
||||
const stats = fs.statSync(tmpdir.resolve('snapshot.blob'));
|
||||
assert(stats.isFile());
|
||||
}
|
||||
@@ -58,9 +56,9 @@ const entry = fixtures.path('snapshot', 'v8-startup-snapshot-api.js');
|
||||
}
|
||||
});
|
||||
|
||||
const stdout = child.stdout.toString().trim();
|
||||
const stderr = child.stderr.toString().trim();
|
||||
assert.strictEqual(stderr, 'Reading book1.en_US.txt');
|
||||
assert.strictEqual(stdout, 'This is book1.en_US.txt');
|
||||
assert.strictEqual(child.status, 0);
|
||||
expectSyncExitWithoutError(child, {
|
||||
stderr: 'Reading book1.en_US.txt',
|
||||
stdout: 'This is book1.en_US.txt',
|
||||
trim: true
|
||||
});
|
||||
}
|
||||
@@ -8,6 +8,7 @@ const assert = require('assert');
|
||||
const { spawnSync } = require('child_process');
|
||||
const tmpdir = require('../common/tmpdir');
|
||||
const fixtures = require('../common/fixtures');
|
||||
const { expectSyncExitWithoutError, expectSyncExit } = require('../common/child_process');
|
||||
const fs = require('fs');
|
||||
|
||||
tmpdir.refresh();
|
||||
@@ -15,7 +16,7 @@ tmpdir.refresh();
|
||||
let snapshotScript = 'node:embedded_snapshot_main';
|
||||
if (!process.config.variables.node_use_node_snapshot) {
|
||||
// Check that Node.js built without an embedded snapshot
|
||||
// exits with 1 when node:embedded_snapshot_main is specified
|
||||
// exits with 9 when node:embedded_snapshot_main is specified
|
||||
// as snapshot entry point.
|
||||
const child = spawnSync(process.execPath, [
|
||||
'--build-snapshot',
|
||||
@@ -24,10 +25,11 @@ if (!process.config.variables.node_use_node_snapshot) {
|
||||
cwd: tmpdir.path
|
||||
});
|
||||
|
||||
assert.match(
|
||||
child.stderr.toString(),
|
||||
/Node\.js was built without embedded snapshot/);
|
||||
assert.strictEqual(child.status, 9);
|
||||
expectSyncExit(child, {
|
||||
status: 9,
|
||||
signal: null,
|
||||
stderr: /Node\.js was built without embedded snapshot/
|
||||
});
|
||||
|
||||
snapshotScript = fixtures.path('empty.js');
|
||||
}
|
||||
@@ -41,12 +43,7 @@ if (!process.config.variables.node_use_node_snapshot) {
|
||||
], {
|
||||
cwd: tmpdir.path
|
||||
});
|
||||
if (child.status !== 0) {
|
||||
console.log(child.stderr.toString());
|
||||
console.log(child.stdout.toString());
|
||||
console.log(child.signal);
|
||||
assert.strictEqual(child.status, 0);
|
||||
}
|
||||
expectSyncExitWithoutError(child);
|
||||
const stats = fs.statSync(tmpdir.resolve('snapshot.blob'));
|
||||
assert(stats.isFile());
|
||||
}
|
||||
@@ -63,12 +60,7 @@ const blobPath = tmpdir.resolve('my-snapshot.blob');
|
||||
], {
|
||||
cwd: tmpdir.path
|
||||
});
|
||||
if (child.status !== 0) {
|
||||
console.log(child.stderr.toString());
|
||||
console.log(child.stdout.toString());
|
||||
console.log(child.signal);
|
||||
assert.strictEqual(child.status, 0);
|
||||
}
|
||||
expectSyncExitWithoutError(child);
|
||||
const stats = fs.statSync(blobPath);
|
||||
assert(stats.isFile());
|
||||
}
|
||||
@@ -82,13 +74,7 @@ const blobPath = tmpdir.resolve('my-snapshot.blob');
|
||||
], {
|
||||
cwd: tmpdir.path
|
||||
});
|
||||
|
||||
if (child.status !== 0) {
|
||||
console.log(child.stderr.toString());
|
||||
console.log(child.stdout.toString());
|
||||
console.log(child.signal);
|
||||
assert.strictEqual(child.status, 0);
|
||||
}
|
||||
expectSyncExitWithoutError(child);
|
||||
|
||||
assert(child.stdout.toString().includes('--help'));
|
||||
}
|
||||
@@ -105,7 +91,9 @@ const blobPath = tmpdir.resolve('my-snapshot.blob');
|
||||
});
|
||||
|
||||
// Check that it is a noop.
|
||||
assert.strictEqual(child.stdout.toString().trim(), '');
|
||||
assert.strictEqual(child.stderr.toString().trim(), '');
|
||||
assert.strictEqual(child.status, 0);
|
||||
expectSyncExitWithoutError(child, {
|
||||
stderr: '',
|
||||
stdout: '',
|
||||
trim: true
|
||||
});
|
||||
}
|
||||
@@ -10,6 +10,7 @@ const assert = require('assert');
|
||||
const { spawnSync } = require('child_process');
|
||||
const tmpdir = require('../common/tmpdir');
|
||||
const fixtures = require('../common/fixtures');
|
||||
const { expectSyncExitWithoutError } = require('../common/child_process');
|
||||
const fs = require('fs');
|
||||
|
||||
const warningScript = fixtures.path('snapshot', 'warning.js');
|
||||
@@ -27,12 +28,7 @@ tmpdir.refresh();
|
||||
], {
|
||||
cwd: tmpdir.path
|
||||
});
|
||||
console.log('[stderr]:', child.stderr.toString());
|
||||
console.log('[stdout]:', child.stdout.toString());
|
||||
if (child.status !== 0) {
|
||||
console.log(child.signal);
|
||||
assert.strictEqual(child.status, 0);
|
||||
}
|
||||
expectSyncExitWithoutError(child);
|
||||
const stats = fs.statSync(blobPath);
|
||||
assert(stats.isFile());
|
||||
|
||||
@@ -43,14 +39,14 @@ tmpdir.refresh();
|
||||
], {
|
||||
cwd: tmpdir.path
|
||||
});
|
||||
console.log('[stderr]:', child.stderr.toString());
|
||||
console.log('[stdout]:', child.stdout.toString());
|
||||
if (child.status !== 0) {
|
||||
console.log(child.signal);
|
||||
assert.strictEqual(child.status, 0);
|
||||
}
|
||||
const match = child.stderr.toString().match(/Warning: test warning/g);
|
||||
assert.strictEqual(match.length, 1);
|
||||
expectSyncExitWithoutError(child, {
|
||||
stderr(output) {
|
||||
const match = output.match(/Warning: test warning/g);
|
||||
assert.strictEqual(match.length, 1);
|
||||
return true;
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
tmpdir.refresh();
|
||||
@@ -65,18 +61,17 @@ tmpdir.refresh();
|
||||
], {
|
||||
cwd: tmpdir.path
|
||||
});
|
||||
console.log('[stderr]:', child.stderr.toString());
|
||||
console.log('[stdout]:', child.stdout.toString());
|
||||
if (child.status !== 0) {
|
||||
console.log(child.signal);
|
||||
assert.strictEqual(child.status, 0);
|
||||
}
|
||||
expectSyncExitWithoutError(child, {
|
||||
stderr(output) {
|
||||
let match = output.match(/Warning: test warning/g);
|
||||
assert.strictEqual(match.length, 1);
|
||||
match = output.match(/Use `node --trace-warnings/g);
|
||||
assert.strictEqual(match.length, 1);
|
||||
return true;
|
||||
}
|
||||
});
|
||||
const stats = fs.statSync(blobPath);
|
||||
assert(stats.isFile());
|
||||
let match = child.stderr.toString().match(/Warning: test warning/g);
|
||||
assert.strictEqual(match.length, 1);
|
||||
match = child.stderr.toString().match(/Use `node --trace-warnings/g);
|
||||
assert.strictEqual(match.length, 1);
|
||||
|
||||
child = spawnSync(process.execPath, [
|
||||
'--snapshot-blob',
|
||||
@@ -85,17 +80,17 @@ tmpdir.refresh();
|
||||
], {
|
||||
cwd: tmpdir.path
|
||||
});
|
||||
console.log('[stderr]:', child.stderr.toString());
|
||||
console.log('[stdout]:', child.stdout.toString());
|
||||
if (child.status !== 0) {
|
||||
console.log(child.signal);
|
||||
assert.strictEqual(child.status, 0);
|
||||
}
|
||||
// Warnings should not be handled more than once.
|
||||
match = child.stderr.toString().match(/Warning: test warning/g);
|
||||
assert.strictEqual(match.length, 1);
|
||||
match = child.stderr.toString().match(/Use `node --trace-warnings/g);
|
||||
assert.strictEqual(match.length, 1);
|
||||
|
||||
expectSyncExitWithoutError(child, {
|
||||
stderr(output) {
|
||||
// Warnings should not be handled more than once.
|
||||
let match = output.match(/Warning: test warning/g);
|
||||
assert.strictEqual(match.length, 1);
|
||||
match = output.match(/Use `node --trace-warnings/g);
|
||||
assert.strictEqual(match.length, 1);
|
||||
return true;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
tmpdir.refresh();
|
||||
@@ -114,25 +109,26 @@ tmpdir.refresh();
|
||||
], {
|
||||
cwd: tmpdir.path
|
||||
});
|
||||
console.log('[stderr]:', child.stderr.toString());
|
||||
console.log('[stdout]:', child.stdout.toString());
|
||||
if (child.status !== 0) {
|
||||
console.log(child.signal);
|
||||
assert.strictEqual(child.status, 0);
|
||||
}
|
||||
|
||||
expectSyncExitWithoutError(child, {
|
||||
stderr(output) {
|
||||
assert.doesNotMatch(output, /Warning: test warning/);
|
||||
}
|
||||
});
|
||||
|
||||
const stats = fs.statSync(blobPath);
|
||||
assert(stats.isFile());
|
||||
|
||||
const warnings1 = fs.readFileSync(warningFile1, 'utf8');
|
||||
console.log(warningFile1, ':', warnings1);
|
||||
let match = warnings1.match(/Warning: test warning/g);
|
||||
assert.strictEqual(match.length, 1);
|
||||
match = warnings1.match(/Use `node --trace-warnings/g);
|
||||
assert.strictEqual(match.length, 1);
|
||||
assert.doesNotMatch(child.stderr.toString(), /Warning: test warning/);
|
||||
|
||||
fs.rmSync(warningFile1, {
|
||||
maxRetries: 3, recursive: false, force: true
|
||||
});
|
||||
|
||||
child = spawnSync(process.execPath, [
|
||||
'--snapshot-blob',
|
||||
blobPath,
|
||||
@@ -142,12 +138,13 @@ tmpdir.refresh();
|
||||
], {
|
||||
cwd: tmpdir.path
|
||||
});
|
||||
console.log('[stderr]:', child.stderr.toString());
|
||||
console.log('[stdout]:', child.stdout.toString());
|
||||
if (child.status !== 0) {
|
||||
console.log(child.signal);
|
||||
assert.strictEqual(child.status, 0);
|
||||
}
|
||||
|
||||
expectSyncExitWithoutError(child, {
|
||||
stderr(output) {
|
||||
assert.doesNotMatch(output, /Warning: test warning/);
|
||||
return true;
|
||||
}
|
||||
});
|
||||
assert(!fs.existsSync(warningFile1));
|
||||
|
||||
const warnings2 = fs.readFileSync(warningFile2, 'utf8');
|
||||
@@ -156,5 +153,4 @@ tmpdir.refresh();
|
||||
assert.strictEqual(match.length, 1);
|
||||
match = warnings2.match(/Use `node --trace-warnings/g);
|
||||
assert.strictEqual(match.length, 1);
|
||||
assert.doesNotMatch(child.stderr.toString(), /Warning: test warning/);
|
||||
}
|
||||
Reference in new issue
Block a user