Skip to content

Commit 37fab8a

Browse files
author
Robert Jackson
committed
Add basic tests for the test command.
1 parent 35307a4 commit 37fab8a

1 file changed

Lines changed: 46 additions & 1 deletion

File tree

tests/cli-test.js

Lines changed: 46 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
const fs = require('fs-extra');
12
const path = require('path');
23
/*eslint-disable node/no-unpublished-require */
34
const createTempDir = require('broccoli-test-helper').createTempDir;
@@ -6,7 +7,8 @@ const execa = require('execa');
67
const walkSync = require('walk-sync');
78
/*eslint-enable*/
89

9-
const EXECUTABLE_PATH = path.join(__dirname, '..', 'bin', 'cli.js');
10+
const PROJECT_ROOT = path.join(__dirname, '..');
11+
const EXECUTABLE_PATH = path.join(PROJECT_ROOT, 'bin', 'cli.js');
1012
const ROOT = process.cwd();
1113

1214
QUnit.module('codemod-cli', function(hooks) {
@@ -64,6 +66,11 @@ QUnit.module('codemod-cli', function(hooks) {
6466

6567
hooks.beforeEach(function() {
6668
input.copy(project.path('test-project'));
69+
70+
// setup required dependencies in the project
71+
fs.ensureDirSync(`${input.path()}/node_modules`);
72+
fs.symlinkSync(`${ROOT}/node_modules/jest`, `${input.path()}/node_modules/jest`);
73+
fs.symlinkSync(PROJECT_ROOT, `${input.path()}/node_modules/codemod-cli`);
6774
});
6875

6976
QUnit.module('codemod', function() {
@@ -110,5 +117,43 @@ QUnit.module('codemod-cli', function(hooks) {
110117
})
111118
);
112119
});
120+
121+
QUnit.module('test', function() {
122+
QUnit.test(
123+
'should pass for a basic project with an empty codemod',
124+
wrap(function*(assert) {
125+
yield execa(EXECUTABLE_PATH, ['generate', 'codemod', 'main']);
126+
yield execa(EXECUTABLE_PATH, ['generate', 'fixture', 'main', 'this-dot-owner']);
127+
128+
let result = yield execa(EXECUTABLE_PATH, ['test']);
129+
assert.equal(result.code, 0, 'exited with zero');
130+
})
131+
);
132+
133+
QUnit.test(
134+
'should fail when input and output do not match',
135+
wrap(function*(assert) {
136+
yield execa(EXECUTABLE_PATH, ['generate', 'codemod', 'main']);
137+
yield execa(EXECUTABLE_PATH, ['generate', 'fixture', 'main', 'this-dot-owner']);
138+
139+
input.write({
140+
transforms: {
141+
main: {
142+
__testfixtures__: {
143+
'basic.input.js': '"starting content";',
144+
'basic.output.js': '"different content";',
145+
},
146+
},
147+
},
148+
});
149+
150+
try {
151+
yield execa(EXECUTABLE_PATH, ['test']);
152+
} catch (result) {
153+
assert.notEqual(result.code, 0, 'exited with non-zero');
154+
}
155+
})
156+
);
157+
});
113158
});
114159
});

0 commit comments

Comments
 (0)