Skip to content

Commit

Permalink
Update dependencies
Browse files Browse the repository at this point in the history
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`
  • Loading branch information
andreyfel committed Dec 29, 2023
1 parent 9818859 commit 15538f9
Show file tree
Hide file tree
Showing 5 changed files with 2,119 additions and 2,868 deletions.
50 changes: 26 additions & 24 deletions lib/commands/exam/iterate.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
'use strict';

const execa = require('execa');

module.exports = {
name: 'exam:iterate',

Expand Down Expand Up @@ -42,24 +40,24 @@ module.exports = {
*
* @override
*/
run(commandOptions, anonymousOptions) {
async run(commandOptions, anonymousOptions) {
const needsBuild = !commandOptions.path;

if (needsBuild) {
this._buildForTests();
await this._buildForTests();
} else {
this._outputDir = commandOptions.path;
}

const numIterations = parseInt(anonymousOptions[0], 10);
const options = commandOptions.options;
const results = this._runIterations(numIterations, options);
const results = await this._runIterations(numIterations, options);

if (needsBuild) {
this._cleanupBuild();
await this._cleanupBuild();
}

this._write(results.toString(), true);
await this._write(results.toString(), true);
},

/**
Expand All @@ -68,9 +66,10 @@ module.exports = {
* @param {String} input
* @param {Boolean} noColor
*/
_write(input, noColor) {
async _write(input, noColor) {
if (!noColor) {
input = require('chalk').blue(input);
const chalk = (await import('chalk')).default;
input = chalk.blue(input);
}

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

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

/**
Expand All @@ -105,8 +106,8 @@ module.exports = {
* @param {String} options
* @return {Table} results
*/
_runIterations(numIterations, options) {
const chalk = require('chalk');
async _runIterations(numIterations, options) {
const chalk = (await import('chalk')).default;
const Table = require('cli-table3');

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

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

this._write('\nRan ' + numIterations + ' iterations.');
await this._write('\nRan ' + numIterations + ' iterations.');

return results;
},
Expand All @@ -135,8 +137,8 @@ module.exports = {
* @param {String} options
* @return {Array} results
*/
_runTests(options) {
const chalk = require('chalk');
async _runTests(options) {
const chalk = (await import('chalk')).default;
const execSync = require('child_process').execSync;

const seed = Math.random().toString(36).slice(2);
Expand All @@ -153,7 +155,7 @@ module.exports = {
execSync(command, { stdio: 'inherit' });
exitCode = 0;
} catch (error) {
this._write('Returned non-zero exit code with error: ' + error);
await this._write('Returned non-zero exit code with error: ' + error);
exitCode = 1;
process.exitCode = 1;
}
Expand Down
116 changes: 60 additions & 56 deletions node-tests/acceptance/exam-iterate-test.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,24 @@
'use strict';

const assert = require('assert');
const execa = require('execa');
const rimraf = require('rimraf');
const { rimrafSync } = require('rimraf');
const fs = require('fs-extra');
const path = require('path');

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

async function execa(command, args) {
const { execa: originalExeca } = await import('execa');
return originalExeca(command, args);
}

describe('Acceptance | Exam Iterate Command', function () {
this.timeout(300000);

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

afterEach(() => rimraf.sync(buildDir));
afterEach(() => rimrafSync(buildDir));

it('should not build the app or clean it up, but use an existing build to test', function () {
execa.sync('ember', ['build']);

return execa('ember', ['exam:iterate', '2', '--path', 'dist']).then(
(child) => {
const stdout = child.stdout;

assert.ok(
!stdout.includes('Building app for test iterations.'),
'No logged building message from command',
);
assert.ok(
!stdout.includes('Built project successfully.'),
'Not built successfully according to Ember-CLI',
);

assert.ok(
stdout.includes('Running iteration #1.'),
'Logs first iteration',
);
assert.ok(
stdout.includes('Running iteration #2.'),
'Logs second iteration',
);

const seedRE = /Randomizing tests with seed: (.*)/g;

const firstSeed = seedRE.exec(stdout)[1];
const secondSeed = seedRE.exec(stdout)[1];

assert.ok(firstSeed, 'first seed exists');
assert.ok(secondSeed, 'second seed exists');
assert.notEqual(
firstSeed,
secondSeed,
'the first and second seeds are not the same',
);

assert.ok(
!stdout.includes('Cleaning up test iterations.'),
'No logged cleaning up message from command',
);
assert.throws(
() => fs.accessSync('iteration-dist', fs.F_OK),
'iteration-dist is non-existent',
);

assert.doesNotThrow(
() => fs.accessSync(buildDir, fs.F_OK),
'dist is not cleaned up',
);
},
);
return execa('ember', ['build']).then(() => {
execa('ember', ['exam:iterate', '2', '--path', 'dist']).then(
(child) => {
const stdout = child.stdout;

assert.ok(
!stdout.includes('Building app for test iterations.'),
'No logged building message from command',
);
assert.ok(
!stdout.includes('Built project successfully.'),
'Not built successfully according to Ember-CLI',
);

assert.ok(
stdout.includes('Running iteration #1.'),
'Logs first iteration',
);
assert.ok(
stdout.includes('Running iteration #2.'),
'Logs second iteration',
);

const seedRE = /Randomizing tests with seed: (.*)/g;

const firstSeed = seedRE.exec(stdout)[1];
const secondSeed = seedRE.exec(stdout)[1];

assert.ok(firstSeed, 'first seed exists');
assert.ok(secondSeed, 'second seed exists');
assert.notEqual(
firstSeed,
secondSeed,
'the first and second seeds are not the same',
);

assert.ok(
!stdout.includes('Cleaning up test iterations.'),
'No logged cleaning up message from command',
);
assert.throws(
() => fs.accessSync('iteration-dist', fs.F_OK),
'iteration-dist is non-existent',
);

assert.doesNotThrow(
() => fs.accessSync(buildDir, fs.F_OK),
'dist is not cleaned up',
);
},
);
});
});
});

Expand Down
16 changes: 10 additions & 6 deletions node-tests/acceptance/exam-test.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,21 @@
'use strict';

const assert = require('assert');
const execa = require('execa');
const fixturify = require('fixturify');
const fs = require('fs-extra');
const path = require('path');
const rimraf = require('rimraf');
const { rimrafSync } = require('rimraf');
const glob = require('glob');

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

async function execa(command, args) {
const { execa: originalExeca } = await import('execa');
return originalExeca(command, args);
}

function getNumberOfTests(str) {
const match = str.match(/# tests ([0-9]+)/);
return match && parseInt(match[1], 10);
Expand All @@ -34,14 +38,14 @@ describe('Acceptance | Exam Command', function () {

before(function () {
// Cleanup any previous runs
rimraf.sync('acceptance-dist');
rimrafSync('acceptance-dist');

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

after(function () {
rimraf.sync('acceptance-dist');
rimrafSync('acceptance-dist');
});

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

after(function () {
rimraf.sync('acceptance-with-load-dist');
rimrafSync('acceptance-with-load-dist');

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

afterEach(function () {
rimraf.sync('failure-dist');
rimrafSync('failure-dist');
fs.removeSync(destPath);
});

Expand Down
Loading

0 comments on commit 15538f9

Please sign in to comment.