forked from cypress-io/cypress
-
Notifications
You must be signed in to change notification settings - Fork 0
/
babelTransform.test.ts
36 lines (32 loc) · 1.03 KB
/
babelTransform.test.ts
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
/// <reference path="../../../../../cli/types/mocha/index.d.ts" />
import * as babel from '@babel/core'
import { expect } from 'chai'
import { createTransformPluginsFileBabelPlugin } from './babelTransform'
describe('babel transform utils', () => {
context('Plugins config babel plugin', () => {
it('injects code into the plugins file based on ast', () => {
const plugin = createTransformPluginsFileBabelPlugin({
RequireAst: babel.template.ast('require("something")'),
IfComponentTestingPluginsAst: babel.template.ast('yey()'),
})
const output = babel.transformSync([
'module.exports = (on, config) => {',
'on("do")',
'}',
].join('\n'), {
plugins: [plugin],
})?.code
expect(output).to.equal([
'require("something");',
'',
'module.exports = (on, config) => {',
' on("do");',
'',
' if (config.testingType === "component") {',
' yey();',
' }',
'};',
].join(`\n`))
})
})
})