This repository has been archived by the owner on Dec 11, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: require default from latest plugins
Also added tests
- Loading branch information
1 parent
11b0a9c
commit 30708ae
Showing
4 changed files
with
172 additions
and
59 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
'use strict'; | ||
|
||
exports.actual = ` | ||
const foo = { baz: 42 }; | ||
const bar = null; | ||
console.log(foo?.baz === 42 && bar?.baz === undefined); | ||
`; | ||
|
||
exports.expected = ` | ||
"use strict"; | ||
const foo = { | ||
baz: 42 | ||
}; | ||
const bar = null; | ||
console.log((foo === null || foo === void 0 ? void 0 : foo.baz) === 42 && (bar === null || bar === void 0 ? void 0 : bar.baz) === undefined); | ||
`; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
'use strict'; | ||
|
||
const fs = require('fs'); | ||
const { transform } = require('@babel/core'); | ||
|
||
describe('fixtures', () => { | ||
const presetPath = require.resolve('.'); | ||
|
||
test('preset is not mocked', () => { | ||
// eslint-disable-next-line global-require, import/no-dynamic-require | ||
const plugins = require(presetPath)(null, { | ||
target: '12', | ||
modules: false, | ||
shippedProposals: false, | ||
}).plugins; | ||
expect(typeof plugins[0]).not.toBe('string'); | ||
}); | ||
|
||
const tests = fs | ||
.readdirSync(`${__dirname}/__tests_fixtures__`) | ||
.filter((name) => name.endsWith('.js')); | ||
|
||
tests.forEach((filename) => { | ||
// eslint-disable-next-line global-require, import/no-dynamic-require | ||
const testContent = require(`${__dirname}/__tests_fixtures__/${filename}`); | ||
|
||
test(testContent.name || filename, () => { | ||
try { | ||
const output = transform(testContent.actual, { | ||
babelrc: false, | ||
presets: [[presetPath, testContent.presetOptions || {}]], | ||
}); | ||
|
||
const actual = output.code.trim(); | ||
const expected = testContent.expected.trim(); | ||
|
||
expect(actual).toBe(expected); | ||
} catch (err) { | ||
if (err._babel && err instanceof SyntaxError) { | ||
console.log(`Unexpected error in test: ${test.name || filename}`); | ||
console.log(`${err.name}: ${err.message}\n${err.codeFrame}`); | ||
// eslint-disable-next-line unicorn/no-process-exit | ||
process.exit(1); | ||
} else { | ||
throw err; | ||
} | ||
} | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters