|
1 | 1 | 'use strict'; |
2 | 2 |
|
3 | | -/* global it, describe */ |
4 | | - |
5 | | -const { runInlineTest } = require('jscodeshift/dist/testUtils'); |
6 | | -const fs = require('fs-extra'); |
7 | | -const path = require('path'); |
8 | | - |
9 | | -function transformDetails(options) { |
10 | | - let root = process.cwd() + `/transforms/${options.name}/`; |
11 | | - |
12 | | - return { |
13 | | - name: options.name, |
14 | | - root, |
15 | | - transformPath: root + 'index.js', |
16 | | - fixtureDir: root + '__testfixtures__/', |
17 | | - }; |
18 | | -} |
19 | | - |
20 | | -function jscodeshiftTest(options) { |
21 | | - let details = transformDetails(options); |
22 | | - |
23 | | - let transform = require(details.transformPath); |
24 | | - |
25 | | - describe(details.name, function() { |
26 | | - fs.readdirSync(details.fixtureDir) |
27 | | - .filter(filename => /\.input$/.test(path.basename(filename, path.extname(filename)))) |
28 | | - .forEach(filename => { |
29 | | - let extension = path.extname(filename); |
30 | | - let testName = filename.replace(`.input${extension}`, ''); |
31 | | - let inputPath = path.join(details.fixtureDir, `${testName}.input${extension}`); |
32 | | - let outputPath = path.join(details.fixtureDir, `${testName}.output${extension}`); |
33 | | - |
34 | | - describe(testName, function() { |
35 | | - it('transforms correctly', function() { |
36 | | - runInlineTest( |
37 | | - transform, |
38 | | - {}, |
39 | | - { source: fs.readFileSync(inputPath, 'utf8') }, |
40 | | - fs.readFileSync(outputPath, 'utf8') |
41 | | - ); |
42 | | - }); |
43 | | - |
44 | | - it('is idempotent', function() { |
45 | | - runInlineTest( |
46 | | - transform, |
47 | | - {}, |
48 | | - { source: fs.readFileSync(outputPath, 'utf8') }, |
49 | | - fs.readFileSync(outputPath, 'utf8') |
50 | | - ); |
51 | | - }); |
52 | | - }); |
53 | | - }); |
54 | | - }); |
55 | | -} |
56 | | - |
57 | | -function runTransformTest(options) { |
58 | | - switch (options.type) { |
59 | | - case 'jscodeshift': |
60 | | - return jscodeshiftTest(options); |
61 | | - } |
62 | | -} |
| 3 | +const TestSupport = require('./test-support'); |
| 4 | +const BinSupport = require('./bin-support'); |
63 | 5 |
|
64 | 6 | module.exports = { |
65 | | - runTransformTest, |
| 7 | + runTransformTest: TestSupport.runTransformTest, |
| 8 | + runTransform: BinSupport.runTransform, |
66 | 9 | }; |
0 commit comments