-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathfourteen-testing-api-test.js
More file actions
executable file
·44 lines (38 loc) · 1.62 KB
/
fourteen-testing-api-test.js
File metadata and controls
executable file
·44 lines (38 loc) · 1.62 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
/* eslint-env: node */
'use strict';
const fs = require('fs');
const path = require('path');
const runInlineTest = require('jscodeshift/dist/testUtils').runInlineTest;
const FourteenTestingAPITransform = require('../fourteen-testing-api');
const fixtureFolder = `${__dirname}/../__testfixtures__/fourteen-testing-api`;
describe('fourteen-testing-api', function() {
fs
.readdirSync(fixtureFolder)
.filter(filename => /\.input\.js$/.test(filename))
.forEach(filename => {
// filename format - the-test-name.option1=foo.option2=bar.input.js
let testNameWithOptions = filename.replace('.input.js', ''), // the-test-name.option1=foo.option2=bar
codeshiftOptions = testNameWithOptions.split('.').slice(1).reduce((p,c) => {p[c.split('=')[0]] = c.split('=')[1]; return p;}, {}), // {option1:foo, option2:bar}
testName = testNameWithOptions.split('.')[0], // the-test-name
inputPath = path.join(fixtureFolder, filename),
outputPath = path.join(fixtureFolder, `${testName}.output.js`);
describe(testName, function() {
it('transforms correctly', function() {
runInlineTest(
FourteenTestingAPITransform,
codeshiftOptions,
{ source: fs.readFileSync(inputPath, 'utf8') },
fs.readFileSync(outputPath, 'utf8')
);
});
it('is idempotent', function() {
runInlineTest(
FourteenTestingAPITransform,
codeshiftOptions,
{ source: fs.readFileSync(outputPath, 'utf8') },
fs.readFileSync(outputPath, 'utf8')
);
});
});
});
});