Skip to content

Commit b04b29d

Browse files
authored
Merge pull request #22 from rwjblue/add-test-for-test
Add basic test for the test command.
2 parents d9db97e + 37fab8a commit b04b29d

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() {
@@ -115,5 +122,43 @@ QUnit.module('codemod-cli', function(hooks) {
115122
})
116123
);
117124
});
125+
126+
QUnit.module('test', function() {
127+
QUnit.test(
128+
'should pass for a basic project with an empty codemod',
129+
wrap(function*(assert) {
130+
yield execa(EXECUTABLE_PATH, ['generate', 'codemod', 'main']);
131+
yield execa(EXECUTABLE_PATH, ['generate', 'fixture', 'main', 'this-dot-owner']);
132+
133+
let result = yield execa(EXECUTABLE_PATH, ['test']);
134+
assert.equal(result.code, 0, 'exited with zero');
135+
})
136+
);
137+
138+
QUnit.test(
139+
'should fail when input and output do not match',
140+
wrap(function*(assert) {
141+
yield execa(EXECUTABLE_PATH, ['generate', 'codemod', 'main']);
142+
yield execa(EXECUTABLE_PATH, ['generate', 'fixture', 'main', 'this-dot-owner']);
143+
144+
input.write({
145+
transforms: {
146+
main: {
147+
__testfixtures__: {
148+
'basic.input.js': '"starting content";',
149+
'basic.output.js': '"different content";',
150+
},
151+
},
152+
},
153+
});
154+
155+
try {
156+
yield execa(EXECUTABLE_PATH, ['test']);
157+
} catch (result) {
158+
assert.notEqual(result.code, 0, 'exited with non-zero');
159+
}
160+
})
161+
);
162+
});
118163
});
119164
});

0 commit comments

Comments
 (0)