|
1 | 1 | 'use strict';
|
2 | 2 |
|
3 |
| -const child = require('child_process'); |
4 |
| -const fs = require('fs'); |
5 |
| -const path = require('path'); |
| 3 | +const { spawn } = require('child_process'); |
| 4 | +const { readFileSync } = require('fs'); |
| 5 | +const { join, resolve } = require('path'); |
6 | 6 | const concat = require('concat-stream');
|
7 |
| -const assert = require('assert'); |
8 |
| -const unassertCommand = path.join(__dirname, '..', 'bin', 'cmd.js'); |
| 7 | +const assert = require('assert').strict; |
| 8 | +const unassertCommand = join(__dirname, '..', 'bin', 'cmd.js'); |
9 | 9 |
|
10 | 10 | function testUnassertCommand (fixtureName) {
|
11 |
| - const fixtureFilepath = path.resolve(__dirname, 'fixtures', fixtureName, 'fixture.js'); |
12 |
| - const expectedFilepath = path.resolve(__dirname, 'fixtures', fixtureName, 'expected.js'); |
13 |
| - const input = fs.readFileSync(fixtureFilepath, 'utf8'); |
14 |
| - const expected = fs.readFileSync(expectedFilepath, 'utf8'); |
| 11 | + const fixtureFilepath = resolve(__dirname, 'fixtures', fixtureName, 'fixture.js'); |
| 12 | + const expectedFilepath = resolve(__dirname, 'fixtures', fixtureName, 'expected.js'); |
| 13 | + const input = readFileSync(fixtureFilepath, 'utf8'); |
| 14 | + const expected = readFileSync(expectedFilepath, 'utf8'); |
15 | 15 | function assertOutputMatches (proc, done) {
|
16 |
| - proc.stdout.pipe(concat(function (output) { |
| 16 | + proc.stdout.pipe(concat((output) => { |
17 | 17 | assert.equal(output.toString('utf8'), expected);
|
18 | 18 | done();
|
19 | 19 | }));
|
20 | 20 | }
|
21 |
| - describe(fixtureName, function () { |
22 |
| - it('open file when filepath is specified', function (done) { |
23 |
| - const proc = child.spawn(unassertCommand, [fixtureFilepath]); |
| 21 | + describe(fixtureName, () => { |
| 22 | + it('open file when filepath is specified', (done) => { |
| 23 | + const proc = spawn(unassertCommand, [fixtureFilepath]); |
24 | 24 | assertOutputMatches(proc, done);
|
25 | 25 | });
|
26 |
| - it('read from stdin when filepath is not specified', function (done) { |
27 |
| - const proc = child.spawn(unassertCommand); |
| 26 | + it('read from stdin when filepath is not specified', (done) => { |
| 27 | + const proc = spawn(unassertCommand); |
28 | 28 | assertOutputMatches(proc, done);
|
29 | 29 | proc.stdin.end(input);
|
30 | 30 | });
|
31 |
| - it('read from stdin when filepath is "-"', function (done) { |
32 |
| - const proc = child.spawn(unassertCommand, ['-']); |
| 31 | + it('read from stdin when filepath is "-"', (done) => { |
| 32 | + const proc = spawn(unassertCommand, ['-']); |
33 | 33 | assertOutputMatches(proc, done);
|
34 | 34 | proc.stdin.end(input);
|
35 | 35 | });
|
36 | 36 | });
|
37 | 37 | }
|
38 | 38 |
|
39 |
| -describe('unassert-cli', function () { |
| 39 | +describe('unassert-cli', () => { |
40 | 40 | testUnassertCommand('func');
|
41 | 41 | testUnassertCommand('commonjs');
|
42 | 42 | testUnassertCommand('commonjs_singlevar');
|
|
0 commit comments