This repository was archived by the owner on Sep 16, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 99
/
Copy pathindex.js
85 lines (67 loc) · 2.75 KB
/
index.js
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
import _ from 'lodash'
import { assert } from 'chai'
import fs from 'fs'
import glob from 'glob'
import path from 'path'
import plugin from '../src/index'
import { transformFileSync } from '@babel/core'
function getLodashId(testPath) {
const postfix = /\b(?:compat|es)\b/.exec(testPath)
return 'lodash' + (postfix ? '-' + postfix : '')
}
function getTestName(testPath) {
return path.basename(testPath).split('-').join(' ')
}
/*----------------------------------------------------------------------------*/
describe('cherry-picked modular builds', function() {
this.timeout(0)
_.each(glob.sync(path.join(__dirname, 'fixtures/*/')), (testPath) => {
const testName = getTestName(testPath)
const lodashId = getLodashId(testName)
const actualPath = path.join(testPath, 'actual.js')
const expectedPath = path.join(testPath, 'expected.js')
it(`should work with ${ testName }`, () => {
const expected = fs.readFileSync(expectedPath, 'utf8')
const actual = transformFileSync(actualPath, {
'plugins': [[plugin, { 'id': [lodashId, '@storybook/addon-links'] }]]
}).code
assert.strictEqual(_.trim(actual), _.trim(expected))
})
})
/*--------------------------------------------------------------------------*/
_.each(glob.sync(path.join(__dirname, 'error-fixtures/*/')), (testPath) => {
const testName = getTestName(testPath)
const actualPath = path.join(testPath, 'actual.js')
it(`should throw an error with ${ testName }`, () => {
const error = _.attempt(() => transformFileSync(actualPath, {
'plugins': [plugin]
}))
assert.ok(_.isError(error))
})
})
/*--------------------------------------------------------------------------*/
_.each(glob.sync(path.join(__dirname, 'mixed-fixtures/*/')), (testPath) => {
const testName = getTestName(testPath)
const actualPath = path.join(testPath, 'actual.js')
const expectedPath = path.join(testPath, 'expected.js')
const optionsPath = path.join(testPath, 'options.json')
const options = fs.existsSync(optionsPath) ? require(optionsPath) : {}
it(`should work with ${ testName }`, () => {
const expected = fs.readFileSync(expectedPath, 'utf8')
const actual = transformFileSync(actualPath, {
'plugins': [[plugin, options]]
}).code
assert.strictEqual(_.trim(actual), _.trim(expected))
})
})
/*--------------------------------------------------------------------------*/
_.each(glob.sync(path.join(__dirname, 'parsing-fixtures/*/')), (testPath) => {
const testName = getTestName(testPath)
const actualPath = path.join(testPath, 'actual.js')
it(`should not error with ${ testName }`, () => {
transformFileSync(actualPath, {
'plugins': [plugin]
})
})
})
})