Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@
"lint": "eslint . --cache",
"release": "release-it",
"test": "codemod-cli test --coverage",
"test:integration": "node ./test/run-test.js",
"test:notelemetry": " node ./test/run-test-without-telemetry.js"
"test:integration": "node ./test/run-test.mjs",
"test:notelemetry": " node ./test/run-test-without-telemetry.mjs"
},
"jest": {
"collectCoverageFrom": [
Expand All @@ -46,7 +46,7 @@
"eslint": "^8.22.0",
"eslint-config-prettier": "^8.5.0",
"eslint-plugin-prettier": "^4.2.1",
"execa": "^5.0.0",
"execa": "^6.1.0",
"jest": "^28.1.3",
"prettier": "^2.7.1",
"release-it": "^15.3.0",
Expand Down
33 changes: 0 additions & 33 deletions test/run-test-without-telemetry.js

This file was deleted.

30 changes: 30 additions & 0 deletions test/run-test-without-telemetry.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/* eslint-disable no-console */
import { execa } from 'execa';
import path from 'path';

// resolved from the root of the project
const inputDir = path.resolve('./test/fixtures/without-telemetry/input');
const binPath = path.resolve('./bin/cli.js');
const execOpts = { cwd: inputDir, stderr: 'inherit' };

console.log('running codemod');

const codemod = execa(binPath, ['app'], execOpts);
codemod.stdout.pipe(process.stdout);
await codemod;

console.log('codemod complete');

console.log('comparing results');

try {
await execa('diff', ['-rq', './app', '../output/app'], execOpts);
} catch (e) {
console.error('codemod did not run successfully');
console.log(e);

process.exit(1);
}

console.log('codemod ran successfully! 🎉');
process.exit(0);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this test have actual assertions? Or is it like a smoke test?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so... unfortunatly the git diff didn't quite fiture out that this was a move-file change. I didn't alter the way the test was working, I'm just changing it to .mjs to make it work with the new execa version.

but from my understanding, this does have an "assertion". If you look at the bit that is calling diff on two folders: https://github.com/ember-codemods/ember-angle-brackets-codemod/pull/502/files#diff-f28f8437ce5be5f9a77df8786489b7522a29c3377687b4feb491253b7044a4e2R21 you'll see that it's testing the "app" folder against a known output folder. That comes from the fixtures folder: https://github.com/ember-codemods/ember-angle-brackets-codemod/tree/master/test/fixtures

essentially I've seen people setup codemod tests like this before and it's just testing an input folder against an expected output at the end, and if they match it's good 🎉

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I hope that answers your question 🎉

59 changes: 0 additions & 59 deletions test/run-test.js

This file was deleted.

58 changes: 58 additions & 0 deletions test/run-test.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/* eslint-disable no-console */

import { spawn } from 'child_process';
import { execa } from 'execa';
import path from 'path';

// resolved from the root of the project
const inputDir = path.resolve('./test/fixtures/input');
const execOpts = { cwd: inputDir, stderr: 'inherit' };


console.log('installing deps');

await execa('rm', ['-rf', 'node_modules'], execOpts);
await execa('yarn', ['install'], execOpts);

console.log('starting serve');

// We use spawn for this one so we can kill it later without throwing an error
const emberServe = spawn('yarn', ['start'], execOpts);
emberServe.stderr.pipe(process.stderr);
emberServe.stdout.pipe(process.stdout);

await new Promise((resolve) => {
emberServe.stdout.on('data', (data) => {
if (data.toString().includes('Build successful')) {
resolve();
}
});
});

console.log('running codemod');

const codemod = execa(
'../../../bin/cli.js',
['--telemetry', 'http://localhost:4200', 'app'],
execOpts
);
codemod.stdout.pipe(process.stdout);
await codemod;

console.log('codemod complete, ending serve');

emberServe.kill('SIGTERM');

console.log('comparing results');

try {
await execa('diff', ['-rq', './app', '../output/app'], execOpts);
} catch (e) {
console.error('codemod did not run successfully');
console.log(e);

process.exit(1);
}

console.log('codemod ran successfully! 🎉');
process.exit(0);
2 changes: 1 addition & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2999,7 +2999,7 @@ esutils@^2.0.2:
resolved "https://registry.yarnpkg.com/esutils/-/esutils-2.0.3.tgz#74d2eb4de0b8da1293711910d50775b9b710ef64"
integrity sha512-kVscqXk4OCp68SZ0dkgEKVi6/8ij300KBWTJq32P/dYeWTSwK41WyTxalN1eRmA5Z9UU/LX9D7FWSmV9SAYx6g==

execa@6.1.0:
execa@6.1.0, execa@^6.1.0:
version "6.1.0"
resolved "https://registry.yarnpkg.com/execa/-/execa-6.1.0.tgz#cea16dee211ff011246556388effa0818394fb20"
integrity sha512-QVWlX2e50heYJcCPG0iWtf8r0xjEYfz/OYLGDYH+IyjWezzPNxz63qNFOu0l4YftGWuizFVZHHs8PrLU5p2IDA==
Expand Down