Skip to content

Commit 5cc7b4f

Browse files
committed
deps(dev): Remove expect and replace with node:assert
1 parent 086e253 commit 5cc7b4f

2 files changed

Lines changed: 66 additions & 65 deletions

File tree

package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
"devDependencies": {
2929
"eslint": "^9.39.2",
3030
"eslint-config-gulp": "^6.0.0",
31-
"expect": "^27.3.1",
3231
"mocha": "^8.4.0",
3332
"nyc": "^15.1.0",
3433
"v8flags": "^4.0.0"

test/index.js

Lines changed: 66 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
var expect = require('expect');
1+
var assert = require('assert');
22
var exec = require('child_process').exec;
33
var os = require('os');
44
var path = require('path');
@@ -8,20 +8,21 @@ var isV8flags = require('../lib/is-v8flags');
88
var remover = require('../lib/remover');
99
var flaggedRespawn = require('../');
1010

11+
1112
describe('flaggedRespawn', function () {
1213
var flags = ['--harmony', '--use-strict', '--stack-size'];
1314

1415
describe('isV8flags', function () {
1516
it('should return true when flag is in v8flags', function (done) {
16-
expect(isV8flags('--harmony', flags)).toEqual(true);
17-
expect(isV8flags('--use-strict', flags)).toEqual(true);
18-
expect(isV8flags('--stack-size', flags)).toEqual(true);
17+
assert.strictEqual(isV8flags('--harmony', flags), true);
18+
assert.strictEqual(isV8flags('--use-strict', flags), true);
19+
assert.strictEqual(isV8flags('--stack-size', flags), true);
1920
done();
2021
});
2122

2223
it('should return false when flag is not in v8flags', function (done) {
23-
expect(isV8flags('--aaa', flags)).toEqual(false);
24-
expect(isV8flags('__use_strict', flags)).toEqual(false);
24+
assert.strictEqual(isV8flags('--aaa', flags), false);
25+
assert.strictEqual(isV8flags('__use_strict', flags), false);
2526
done();
2627
});
2728
});
@@ -30,32 +31,32 @@ describe('flaggedRespawn', function () {
3031
it('should re-order args, placing special flags first', function (done) {
3132
var needsRespawn = ['node', 'file.js', '--flag', '--harmony', 'command'];
3233
var noRespawnNeeded = ['node', 'bin/flagged-respawn', 'thing'];
33-
expect(reorder(flags, needsRespawn)).toEqual([
34+
assert.deepStrictEqual(reorder(flags, needsRespawn), [
3435
'node',
3536
'--harmony',
3637
'file.js',
3738
'--flag',
3839
'command',
3940
]);
40-
expect(reorder(flags, noRespawnNeeded)).toEqual(noRespawnNeeded);
41+
assert.deepStrictEqual(reorder(flags, noRespawnNeeded), noRespawnNeeded);
4142
done();
4243
});
4344

4445
it('should keep flags values when not placed first', function (done) {
4546
var args = ['node', 'file.js', '--stack-size=2048'];
4647
var expected = ['node', '--stack-size=2048', 'file.js'];
47-
expect(reorder(flags, args)).toEqual(expected);
48+
assert.deepStrictEqual(reorder(flags, args), expected);
4849
done();
4950
});
5051

5152
it('should ignore special flags when they are in the correct position', function (done) {
5253
var args = ['node', '--harmony', 'file.js', '--flag'];
53-
expect(reorder(flags, reorder(flags, args))).toEqual(args);
54+
assert.deepStrictEqual(reorder(flags, reorder(flags, args)), args);
5455
done();
5556
});
5657

5758
it('defaults to process.argv if none specified', function (done) {
58-
expect(reorder(flags)).toEqual(process.argv);
59+
assert.deepStrictEqual(reorder(flags), process.argv);
5960
done();
6061
});
6162
});
@@ -64,64 +65,65 @@ describe('flaggedRespawn', function () {
6465
it('should remove args included in flags', function (done) {
6566
var needsRespawn = ['node', 'file.js', '--flag', '--harmony', 'command'];
6667
var noRespawnNeeded = ['node', 'bin/flagged-respawn', 'thing'];
67-
expect(remover(flags, needsRespawn)).toEqual([
68+
assert.deepStrictEqual(remover(flags, needsRespawn), [
6869
'node',
6970
'file.js',
7071
'--flag',
7172
'command',
7273
]);
73-
expect(reorder(flags, noRespawnNeeded)).toEqual(noRespawnNeeded);
74+
assert.deepStrictEqual(reorder(flags, noRespawnNeeded), noRespawnNeeded);
7475
done();
7576
});
7677

7778
it('should remove a arg even when the arg has value', function (done) {
7879
var args = ['node', 'file.js', '--stack-size=2048'];
7980
var expected = ['node', 'file.js'];
80-
expect(remover(flags, args)).toEqual(expected);
81+
assert.deepStrictEqual(remover(flags, args), expected);
8182
done();
8283
});
8384

8485
it('should remove special flags when they are in the correct position', function (done) {
8586
var args = ['node', '--harmony', 'file.js', '--flag'];
8687
var expected = ['node', 'file.js', '--flag'];
87-
expect(reorder(flags, remover(flags, args))).toEqual(expected);
88+
assert.deepStrictEqual(reorder(flags, remover(flags, args)), expected);
8889
done();
8990
});
9091
});
9192

9293
describe('main export', function () {
9394
it('should throw if no flags are specified', function (done) {
94-
expect(function () {
95+
assert.throws(function () {
9596
flaggedRespawn();
96-
}).toThrow();
97+
});
9798
done();
9899
});
99100

100101
it('should throw if no argv is specified', function (done) {
101-
expect(function () {
102+
assert.throws(function () {
102103
flaggedRespawn(flags);
103-
}).toThrow();
104+
});
104105
done();
105106
});
106107

107108
it('should respawn and pipe stderr/stdout to parent', function (done) {
108109
exec('node ./test/bin/respawner.js --harmony', function (err, stdout) {
109-
expect(stdout.replace(/[0-9]/g, '')).toEqual(
110-
'Special flags found, respawning.\nRespawned to PID: \nRunning!\n'
110+
assert.strictEqual(
111+
stdout.replace(/[0-9]/g, ''),
112+
'Special flags found, respawning.\nRespawned to PID: \nRunning!\n',
111113
);
112114
done();
113115
});
114116
});
115117

116118
it('should respawn and pass exit code from child to parent', function (done) {
117119
exec('node ./test/bin/exit_code.js --harmony', function (err) {
118-
expect(err.code).toEqual(100);
120+
assert.strictEqual(err.code, 100);
119121
done();
120122
});
121123
});
122124

123125
it('should respawn; if child is killed, parent should exit with same signal', function (done) {
124-
// Because travis and nyc hates this
126+
// Because CI and nyc hates this
125127
if (process.env.NYC_PARENT_PID || process.env.NYC_PROCESS_ID) {
126128
this.skip();
127129
return;
@@ -133,11 +135,11 @@ describe('flaggedRespawn', function () {
133135
// Is this related to the issue #12378 of nodejs/node?
134136
case 'win32':
135137
case 'linux': {
136-
expect(err.signal).toEqual(null);
138+
assert.strictEqual(err.signal, null);
137139
break;
138140
}
139141
default: {
140-
expect(err.signal).toEqual('SIGHUP');
142+
assert.strictEqual(err.signal, 'SIGHUP');
141143
break;
142144
}
143145
}
@@ -148,45 +150,45 @@ describe('flaggedRespawn', function () {
148150
it('should call back with ready as true when respawn is not needed', function (done) {
149151
var argv = ['node', './test/bin/respawner'];
150152
flaggedRespawn(flags, argv, function (ready) {
151-
expect(ready).toEqual(true);
153+
assert.strictEqual(ready, true);
152154
});
153155
done();
154156
});
155157

156158
it('should call back with ready as false when respawn is needed', function (done) {
157159
var argv = ['node', './test/bin/callback-params', '--harmony'];
158160
exec(argv.join(' '), function (err, stdout, stderr) {
159-
expect(err).toEqual(null);
160-
expect(stderr).toEqual('');
161+
assert.strictEqual(err, null);
162+
assert.strictEqual(stderr, '');
161163
var results = stdout.slice(0, -1).split('\n');
162-
expect(results.length).toEqual(2);
163-
expect(JSON.parse(results[0]).ready).toEqual(false);
164-
expect(JSON.parse(results[1]).ready).toEqual(true);
164+
assert.strictEqual(results.length, 2);
165+
assert.strictEqual(JSON.parse(results[0]).ready, false);
166+
assert.strictEqual(JSON.parse(results[1]).ready, true);
165167
done();
166168
});
167169
});
168170

169171
it('should call back with the child process when ready', function (done) {
170172
var argv = ['node', './test/bin/callback-params', '--harmony'];
171173
exec(argv.join(' '), function (err, stdout, stderr) {
172-
expect(err).toEqual(null);
173-
expect(stderr).toEqual('');
174+
assert.strictEqual(err, null);
175+
assert.strictEqual(stderr, '');
174176
var results = stdout.slice(0, -1).split('\n');
175-
expect(results.length).toEqual(2);
177+
assert.strictEqual(results.length, 2);
176178

177179
var params = JSON.parse(results[0]);
178-
expect(params.child_pid).not.toEqual(params.process_pid);
180+
assert.notStrictEqual(params.child_pid, params.process_pid);
179181

180182
params = JSON.parse(results[1]);
181-
expect(params.child_pid).toEqual(params.process_pid);
183+
assert.strictEqual(params.child_pid, params.process_pid);
182184
done();
183185
});
184186
});
185187

186188
it('should call back with own process when respawn not needed', function (done) {
187189
var argv = ['node', './test/bin/respawner'];
188190
flaggedRespawn(flags, argv, function (ready, child) {
189-
expect(child.pid).toEqual(process.pid);
191+
assert.strictEqual(child.pid, process.pid);
190192
});
191193

192194
done();
@@ -203,9 +205,9 @@ describe('flaggedRespawn', function () {
203205
].join(' ');
204206

205207
exec(cmd, function cb(err, stdout, stderr) {
206-
expect(err).toEqual(null);
207-
expect(stderr).toEqual('');
208-
expect(stdout).toEqual('Running!\n');
208+
assert.strictEqual(err, null);
209+
assert.strictEqual(stderr, '');
210+
assert.strictEqual(stdout, 'Running!\n');
209211
done();
210212
});
211213
});
@@ -218,9 +220,9 @@ describe('flaggedRespawn', function () {
218220
].join(' ');
219221

220222
exec(cmd, function cb(err, stdout, stderr) {
221-
expect(err).toEqual(null);
222-
expect(stderr).toEqual('');
223-
expect(stdout).toEqual('Running!\n');
223+
assert.strictEqual(err, null);
224+
assert.strictEqual(stderr, '');
225+
assert.strictEqual(stdout, 'Running!\n');
224226
done();
225227
});
226228
});
@@ -232,9 +234,9 @@ describe('flaggedRespawn', function () {
232234
].join(' ');
233235

234236
exec(cmd, function cb(err, stdout, stderr) {
235-
expect(err).toEqual(null);
236-
expect(stderr).toEqual('');
237-
expect(stdout).toEqual('Respawning!\nRunning!\n');
237+
assert.strictEqual(err, null);
238+
assert.strictEqual(stderr, '');
239+
assert.strictEqual(stdout, 'Respawning!\nRunning!\n');
238240
done();
239241
});
240242
});
@@ -246,9 +248,9 @@ describe('flaggedRespawn', function () {
246248
].join(' ');
247249

248250
exec(cmd, function cb(err, stdout, stderr) {
249-
expect(err).toEqual(null);
250-
expect(stderr).toEqual('');
251-
expect(stdout).toEqual('Respawning!\nRunning!\n');
251+
assert.strictEqual(err, null);
252+
assert.strictEqual(stderr, '');
253+
assert.strictEqual(stdout, 'Respawning!\nRunning!\n');
252254
done();
253255
});
254256
});
@@ -257,9 +259,9 @@ describe('flaggedRespawn', function () {
257259
exec('node ./test/bin/force-and-forbid-respawning.js', cb);
258260

259261
function cb(err, stdout, stderr) {
260-
expect(err).toEqual(null);
261-
expect(stderr).toEqual('');
262-
expect(stdout).toEqual('Running!\n');
262+
assert.strictEqual(err, null);
263+
assert.strictEqual(stderr, '');
264+
assert.strictEqual(stdout, 'Running!\n');
263265
done();
264266
}
265267
});
@@ -297,9 +299,9 @@ describe('flaggedRespawn', function () {
297299
'\n';
298300

299301
exec(cmd, function cb(err, stdout, stderr) {
300-
expect(err).toEqual(null);
301-
expect(stderr).toEqual('');
302-
expect(stdout).toEqual(message);
302+
assert.strictEqual(err, null);
303+
assert.strictEqual(stderr, '');
304+
assert.strictEqual(stdout, message);
303305
done();
304306
});
305307
});
@@ -335,9 +337,9 @@ describe('flaggedRespawn', function () {
335337
'\n';
336338

337339
exec(cmd, function cb(err, stdout, stderr) {
338-
expect(err).toEqual(null);
339-
expect(stderr).toEqual('');
340-
expect(stdout).toEqual(message);
340+
assert.strictEqual(err, null);
341+
assert.strictEqual(stderr, '');
342+
assert.strictEqual(stdout, message);
341343
done();
342344
});
343345
});
@@ -348,13 +350,13 @@ describe('flaggedRespawn', function () {
348350
var argv = ['node', './test/bin/respawner'];
349351
var exec = function () {};
350352

351-
expect(function () {
353+
assert.throws(function () {
352354
flaggedRespawn(null, argv, exec);
353-
}).toThrow(Error);
355+
});
354356

355-
expect(function () {
357+
assert.throws(function () {
356358
flaggedRespawn(flags, undefined, exec);
357-
}).toThrow(Error);
359+
});
358360

359361
done();
360362
});
@@ -363,8 +365,8 @@ describe('flaggedRespawn', function () {
363365
var argv = ['node', './test/bin/respawner'];
364366

365367
flaggedRespawn(flags, argv, {}, function (ready, child) {
366-
expect(ready).toEqual(true);
367-
expect(child.pid).toEqual(process.pid);
368+
assert.strictEqual(ready, true);
369+
assert.strictEqual(child.pid, process.pid);
368370
done();
369371
});
370372
});

0 commit comments

Comments
 (0)