Skip to content

Commit 15538f9

Browse files
author
Andrey Fel
committed
Update dependencies
Update all dependencies to the latest `execa` and `chalk` are ESM now, thus we need to import them asynchronously. `rimraf` offers different imports now `istanbul` is not needed as a dependency as `nyc` is used instead. `release-it-lerna-changelog` was renamed to `@release-it-plugins/lerna-changelog` `testdouble` wasn't used anywhere `yarn upgrade`
1 parent 9818859 commit 15538f9

5 files changed

Lines changed: 2119 additions & 2868 deletions

File tree

lib/commands/exam/iterate.js

Lines changed: 26 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
'use strict';
22

3-
const execa = require('execa');
4-
53
module.exports = {
64
name: 'exam:iterate',
75

@@ -42,24 +40,24 @@ module.exports = {
4240
*
4341
* @override
4442
*/
45-
run(commandOptions, anonymousOptions) {
43+
async run(commandOptions, anonymousOptions) {
4644
const needsBuild = !commandOptions.path;
4745

4846
if (needsBuild) {
49-
this._buildForTests();
47+
await this._buildForTests();
5048
} else {
5149
this._outputDir = commandOptions.path;
5250
}
5351

5452
const numIterations = parseInt(anonymousOptions[0], 10);
5553
const options = commandOptions.options;
56-
const results = this._runIterations(numIterations, options);
54+
const results = await this._runIterations(numIterations, options);
5755

5856
if (needsBuild) {
59-
this._cleanupBuild();
57+
await this._cleanupBuild();
6058
}
6159

62-
this._write(results.toString(), true);
60+
await this._write(results.toString(), true);
6361
},
6462

6563
/**
@@ -68,9 +66,10 @@ module.exports = {
6866
* @param {String} input
6967
* @param {Boolean} noColor
7068
*/
71-
_write(input, noColor) {
69+
async _write(input, noColor) {
7270
if (!noColor) {
73-
input = require('chalk').blue(input);
71+
const chalk = (await import('chalk')).default;
72+
input = chalk.blue(input);
7473
}
7574

7675
console.info(input); // eslint-disable-line no-console
@@ -80,21 +79,23 @@ module.exports = {
8079
* Builds the application into a special output directory to run the tests
8180
* against repeatedly without rebuilding.
8281
*/
83-
_buildForTests() {
84-
this._write('\nBuilding app for test iterations.');
85-
execa.sync(
82+
async _buildForTests() {
83+
await this._write('\nBuilding app for test iterations.');
84+
const { execa } = await import('execa');
85+
await execa(
8686
'./node_modules/.bin/ember',
8787
['build', '--output-path', `${this._outputDir}`],
88-
['stdio', 'inherit'],
88+
{ stdio: 'inherit' },
8989
);
9090
},
9191

9292
/**
9393
* Cleans up the build artifacts used for the test iterations.
9494
*/
95-
_cleanupBuild() {
96-
this._write('\nCleaning up test iterations.\n');
97-
execa.sync('rm', ['-rf', `${this._outputDir}`]);
95+
async _cleanupBuild() {
96+
await this._write('\nCleaning up test iterations.\n');
97+
const { execa } = await import('execa');
98+
await execa('rm', ['-rf', `${this._outputDir}`]);
9899
},
99100

100101
/**
@@ -105,8 +106,8 @@ module.exports = {
105106
* @param {String} options
106107
* @return {Table} results
107108
*/
108-
_runIterations(numIterations, options) {
109-
const chalk = require('chalk');
109+
async _runIterations(numIterations, options) {
110+
const chalk = (await import('chalk')).default;
110111
const Table = require('cli-table3');
111112

112113
const results = new Table({
@@ -119,11 +120,12 @@ module.exports = {
119120
});
120121

121122
for (let i = 0; i < numIterations; i++) {
122-
this._write('\nRunning iteration #' + (i + 1) + '.');
123-
results.push([i].concat(this._runTests(options)));
123+
await this._write('\nRunning iteration #' + (i + 1) + '.');
124+
const result = await this._runTests(options);
125+
results.push([i].concat(result));
124126
}
125127

126-
this._write('\nRan ' + numIterations + ' iterations.');
128+
await this._write('\nRan ' + numIterations + ' iterations.');
127129

128130
return results;
129131
},
@@ -135,8 +137,8 @@ module.exports = {
135137
* @param {String} options
136138
* @return {Array} results
137139
*/
138-
_runTests(options) {
139-
const chalk = require('chalk');
140+
async _runTests(options) {
141+
const chalk = (await import('chalk')).default;
140142
const execSync = require('child_process').execSync;
141143

142144
const seed = Math.random().toString(36).slice(2);
@@ -153,7 +155,7 @@ module.exports = {
153155
execSync(command, { stdio: 'inherit' });
154156
exitCode = 0;
155157
} catch (error) {
156-
this._write('Returned non-zero exit code with error: ' + error);
158+
await this._write('Returned non-zero exit code with error: ' + error);
157159
exitCode = 1;
158160
process.exitCode = 1;
159161
}

node-tests/acceptance/exam-iterate-test.js

Lines changed: 60 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,24 @@
11
'use strict';
22

33
const assert = require('assert');
4-
const execa = require('execa');
5-
const rimraf = require('rimraf');
4+
const { rimrafSync } = require('rimraf');
65
const fs = require('fs-extra');
76
const path = require('path');
87

98
function assertExpectRejection() {
109
assert.ok(false, 'Expected promise to reject, but it fullfilled');
1110
}
1211

12+
async function execa(command, args) {
13+
const { execa: originalExeca } = await import('execa');
14+
return originalExeca(command, args);
15+
}
16+
1317
describe('Acceptance | Exam Iterate Command', function () {
1418
this.timeout(300000);
1519

1620
it('should build the app, test it a number of times, and clean it up', function () {
17-
return execa('ember', ['exam:iterate', '2'], (child) => {
21+
return execa('ember', ['exam:iterate', '2']).then((child) => {
1822
const stdout = child.stdout;
1923
assert.ok(
2024
stdout.includes('Building app for test iterations.'),
@@ -82,61 +86,61 @@ describe('Acceptance | Exam Iterate Command', function () {
8286
describe('building', function () {
8387
const buildDir = path.join(process.cwd(), 'dist');
8488

85-
afterEach(() => rimraf.sync(buildDir));
89+
afterEach(() => rimrafSync(buildDir));
8690

8791
it('should not build the app or clean it up, but use an existing build to test', function () {
88-
execa.sync('ember', ['build']);
89-
90-
return execa('ember', ['exam:iterate', '2', '--path', 'dist']).then(
91-
(child) => {
92-
const stdout = child.stdout;
93-
94-
assert.ok(
95-
!stdout.includes('Building app for test iterations.'),
96-
'No logged building message from command',
97-
);
98-
assert.ok(
99-
!stdout.includes('Built project successfully.'),
100-
'Not built successfully according to Ember-CLI',
101-
);
102-
103-
assert.ok(
104-
stdout.includes('Running iteration #1.'),
105-
'Logs first iteration',
106-
);
107-
assert.ok(
108-
stdout.includes('Running iteration #2.'),
109-
'Logs second iteration',
110-
);
111-
112-
const seedRE = /Randomizing tests with seed: (.*)/g;
113-
114-
const firstSeed = seedRE.exec(stdout)[1];
115-
const secondSeed = seedRE.exec(stdout)[1];
116-
117-
assert.ok(firstSeed, 'first seed exists');
118-
assert.ok(secondSeed, 'second seed exists');
119-
assert.notEqual(
120-
firstSeed,
121-
secondSeed,
122-
'the first and second seeds are not the same',
123-
);
124-
125-
assert.ok(
126-
!stdout.includes('Cleaning up test iterations.'),
127-
'No logged cleaning up message from command',
128-
);
129-
assert.throws(
130-
() => fs.accessSync('iteration-dist', fs.F_OK),
131-
'iteration-dist is non-existent',
132-
);
133-
134-
assert.doesNotThrow(
135-
() => fs.accessSync(buildDir, fs.F_OK),
136-
'dist is not cleaned up',
137-
);
138-
},
139-
);
92+
return execa('ember', ['build']).then(() => {
93+
execa('ember', ['exam:iterate', '2', '--path', 'dist']).then(
94+
(child) => {
95+
const stdout = child.stdout;
96+
97+
assert.ok(
98+
!stdout.includes('Building app for test iterations.'),
99+
'No logged building message from command',
100+
);
101+
assert.ok(
102+
!stdout.includes('Built project successfully.'),
103+
'Not built successfully according to Ember-CLI',
104+
);
105+
106+
assert.ok(
107+
stdout.includes('Running iteration #1.'),
108+
'Logs first iteration',
109+
);
110+
assert.ok(
111+
stdout.includes('Running iteration #2.'),
112+
'Logs second iteration',
113+
);
114+
115+
const seedRE = /Randomizing tests with seed: (.*)/g;
116+
117+
const firstSeed = seedRE.exec(stdout)[1];
118+
const secondSeed = seedRE.exec(stdout)[1];
119+
120+
assert.ok(firstSeed, 'first seed exists');
121+
assert.ok(secondSeed, 'second seed exists');
122+
assert.notEqual(
123+
firstSeed,
124+
secondSeed,
125+
'the first and second seeds are not the same',
126+
);
127+
128+
assert.ok(
129+
!stdout.includes('Cleaning up test iterations.'),
130+
'No logged cleaning up message from command',
131+
);
132+
assert.throws(
133+
() => fs.accessSync('iteration-dist', fs.F_OK),
134+
'iteration-dist is non-existent',
135+
);
136+
137+
assert.doesNotThrow(
138+
() => fs.accessSync(buildDir, fs.F_OK),
139+
'dist is not cleaned up',
140+
);
141+
},
142+
);
143+
});
140144
});
141145
});
142146

node-tests/acceptance/exam-test.js

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,21 @@
11
'use strict';
22

33
const assert = require('assert');
4-
const execa = require('execa');
54
const fixturify = require('fixturify');
65
const fs = require('fs-extra');
76
const path = require('path');
8-
const rimraf = require('rimraf');
7+
const { rimrafSync } = require('rimraf');
98
const glob = require('glob');
109

1110
function assertExpectRejection() {
1211
assert.ok(false, 'Expected promise to reject, but it fullfilled');
1312
}
1413

14+
async function execa(command, args) {
15+
const { execa: originalExeca } = await import('execa');
16+
return originalExeca(command, args);
17+
}
18+
1519
function getNumberOfTests(str) {
1620
const match = str.match(/# tests ([0-9]+)/);
1721
return match && parseInt(match[1], 10);
@@ -34,14 +38,14 @@ describe('Acceptance | Exam Command', function () {
3438

3539
before(function () {
3640
// Cleanup any previous runs
37-
rimraf.sync('acceptance-dist');
41+
rimrafSync('acceptance-dist');
3842

3943
// Build the app
4044
return execa('ember', ['build', '--output-path', 'acceptance-dist']);
4145
});
4246

4347
after(function () {
44-
rimraf.sync('acceptance-dist');
48+
rimrafSync('acceptance-dist');
4549
});
4650

4751
function assertOutput(output, text, good, bad) {
@@ -131,7 +135,7 @@ describe('Acceptance | Exam Command', function () {
131135
});
132136

133137
after(function () {
134-
rimraf.sync('acceptance-with-load-dist');
138+
rimrafSync('acceptance-with-load-dist');
135139

136140
// restore the original test-helper.js file
137141
fs.unlinkSync(originalTestHelperPath);
@@ -452,7 +456,7 @@ describe('Acceptance | Exam Command', function () {
452456
});
453457

454458
afterEach(function () {
455-
rimraf.sync('failure-dist');
459+
rimrafSync('failure-dist');
456460
fs.removeSync(destPath);
457461
});
458462

0 commit comments

Comments
 (0)