-
-
Notifications
You must be signed in to change notification settings - Fork 5
/
main.js
46 lines (45 loc) · 1.88 KB
/
main.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
const transformFileSync = require('@babel/core').transformFileSync
const path = require('path')
const fs = require('fs')
const assert = require('assert')
const plugin = require('../dist/index').default
const tests = [
{ file: 'test1' },
{ file: 'map' },
{ file: 'nonDefaultLogger' },
{ file: 'nonDefaultLogger2' },
{ file: 'nested/really-nested/fullPath' },
{ file: 'nested/really-nested/longerPath', options: { maxDepth: 2 } },
{ file: 'nested/really-nested/shortPath', options: { maxDepth: 1 } },
{ file: 'nested/really-nested/maxDepthLongerThanNecessary', options: { maxDepth: 6 } },
{ file: 'test1', options: { loggers: [ { pattern: 'console' } ] } },
{ file: 'readLoggerFromOptions', options: { loggers: [ { pattern: 'winston' } ] } }
]
describe('transform code', function () {
describe('No preset', function () {
tests.forEach(function (test) {
;(test.only ? it.only : it)(`${test.file}`, function (done) {
const transform = transformFileSync(path.join('test/src/', `${test.file}.js`), {
plugins: [ [ plugin, test.options ] ],
babelrc: false // So we don't get babelrc from whole project
}).code
const expected = fs.readFileSync(path.join(__dirname, 'expected', `${test.file}.js`)).toString()
assert.strictEqual(transform, expected)
done()
})
})
})
describe('Absolute path', function () {
tests.forEach(function (test) {
;(test.only ? it.only : it)(`${test.file}`, function (done) {
const transform = transformFileSync(path.join(__dirname, 'src', `${test.file}.js`), {
plugins: [ [ plugin, test.options ] ],
babelrc: false // So we don't get babelrc from whole project
}).code
const expected = fs.readFileSync(path.join(__dirname, 'expected', `${test.file}.js`)).toString()
assert.strictEqual(transform, expected)
done()
})
})
})
})