Skip to content

Commit a89493f

Browse files
authored
Merge pull request #119 from jbryson3/feature/standardize-test-runners
Standardizing testing methodology
2 parents 90451be + 0609331 commit a89493f

2 files changed

Lines changed: 73 additions & 13 deletions

File tree

__tests__/import-it-from-mocha-test.js

100755100644
Lines changed: 37 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,40 @@
1+
/* eslint-env: node */
12
'use strict';
23

3-
const defineTest = require('jscodeshift/dist/testUtils').defineTest;
4+
const fs = require('fs');
5+
const path = require('path');
46

5-
defineTest(__dirname, 'import-it-from-mocha', {}, 'import-it-from-mocha/basic');
6-
defineTest(__dirname, 'import-it-from-mocha', {}, 'import-it-from-mocha/test-helper');
7-
defineTest(__dirname, 'import-it-from-mocha', {}, 'import-it-from-mocha/with-comment');
8-
defineTest(__dirname, 'import-it-from-mocha', {}, 'import-it-from-mocha/with-comment2');
9-
defineTest(__dirname, 'import-it-from-mocha', {}, 'import-it-from-mocha/with-comment3');
10-
defineTest(__dirname, 'import-it-from-mocha', {}, 'import-it-from-mocha/with-other-imports');
7+
const runInlineTest = require('jscodeshift/dist/testUtils').runInlineTest;
8+
const ImportItFromMochaTransform = require('../import-it-from-mocha');
9+
const fixtureFolder = `${__dirname}/../__testfixtures__/import-it-from-mocha`;
10+
11+
describe('import-it-from-mocha', function() {
12+
fs
13+
.readdirSync(fixtureFolder)
14+
.filter(filename => /\.input\.js$/.test(filename))
15+
.forEach(filename => {
16+
let testName = filename.replace('.input.js', '');
17+
let inputPath = path.join(fixtureFolder, `${testName}.input.js`);
18+
let outputPath = path.join(fixtureFolder, `${testName}.output.js`);
19+
20+
describe(testName, function() {
21+
it('transforms correctly', function() {
22+
runInlineTest(
23+
ImportItFromMochaTransform,
24+
{},
25+
{ source: fs.readFileSync(inputPath, 'utf8') },
26+
fs.readFileSync(outputPath, 'utf8')
27+
);
28+
});
29+
30+
it('is idempotent', function() {
31+
runInlineTest(
32+
ImportItFromMochaTransform,
33+
{},
34+
{ source: fs.readFileSync(outputPath, 'utf8') },
35+
fs.readFileSync(outputPath, 'utf8')
36+
);
37+
});
38+
});
39+
});
40+
});

__tests__/new-testing-api-test.js

100755100644
Lines changed: 36 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,40 @@
1+
/* eslint-env: node */
12
'use strict';
23

3-
const defineTest = require('jscodeshift/dist/testUtils').defineTest;
4+
const fs = require('fs');
5+
const path = require('path');
46

5-
defineTest(__dirname, 'new-testing-api', {}, 'new-testing-api/component-test');
6-
defineTest(__dirname, 'new-testing-api', {}, 'new-testing-api/model-test');
7-
defineTest(__dirname, 'new-testing-api', {}, 'new-testing-api/route-test');
8-
defineTest(__dirname, 'new-testing-api', {}, 'new-testing-api/test-helper');
7+
const runInlineTest = require('jscodeshift/dist/testUtils').runInlineTest;
8+
const NewTestingAPITransform = require('../new-testing-api');
9+
const fixtureFolder = `${__dirname}/../__testfixtures__/new-testing-api`;
910

10-
defineTest(__dirname, 'new-testing-api', {}, 'new-testing-api/irrelevant-file');
11+
describe('new-testing-api', function() {
12+
fs
13+
.readdirSync(fixtureFolder)
14+
.filter(filename => /\.input\.js$/.test(filename))
15+
.forEach(filename => {
16+
let testName = filename.replace('.input.js', '');
17+
let inputPath = path.join(fixtureFolder, `${testName}.input.js`);
18+
let outputPath = path.join(fixtureFolder, `${testName}.output.js`);
19+
20+
describe(testName, function() {
21+
it('transforms correctly', function() {
22+
runInlineTest(
23+
NewTestingAPITransform,
24+
{},
25+
{ source: fs.readFileSync(inputPath, 'utf8') },
26+
fs.readFileSync(outputPath, 'utf8')
27+
);
28+
});
29+
30+
it('is idempotent', function() {
31+
runInlineTest(
32+
NewTestingAPITransform,
33+
{},
34+
{ source: fs.readFileSync(outputPath, 'utf8') },
35+
fs.readFileSync(outputPath, 'utf8')
36+
);
37+
});
38+
});
39+
});
40+
});

0 commit comments

Comments
 (0)