mirror of
https://github.com/microsoft/playwright.git
synced 2025-06-26 21:40:17 +00:00
fix(runner): import export assignment from ts (#19559)
This commit is contained in:
parent
467d9f37fc
commit
00ffd74727
@ -14,7 +14,9 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import type { BabelFileResult } from '@babel/core';
|
||||
import type { BabelFileResult, NodePath, PluginObj } from '@babel/core';
|
||||
import type { TSExportAssignment } from '@babel/types';
|
||||
import type { TemplateBuilder } from '@babel/template';
|
||||
import * as babel from '@babel/core';
|
||||
|
||||
export { codeFrameColumns } from '@babel/code-frame';
|
||||
@ -39,7 +41,22 @@ export function babelTransform(filename: string, isTypeScript: boolean, isModule
|
||||
[require('@babel/plugin-syntax-optional-catch-binding')],
|
||||
[require('@babel/plugin-syntax-async-generators')],
|
||||
[require('@babel/plugin-syntax-object-rest-spread')],
|
||||
[require('@babel/plugin-proposal-export-namespace-from')]
|
||||
[require('@babel/plugin-proposal-export-namespace-from')],
|
||||
[
|
||||
// From https://github.com/G-Rath/babel-plugin-replace-ts-export-assignment/blob/8dfdca32c8aa428574b0cae341444fc5822f2dc6/src/index.ts
|
||||
(
|
||||
{ template }: { template: TemplateBuilder<TSExportAssignment> }
|
||||
): PluginObj => ({
|
||||
name: 'replace-ts-export-assignment',
|
||||
visitor: {
|
||||
TSExportAssignment(path: NodePath<TSExportAssignment>) {
|
||||
path.replaceWith(template('module.exports = ASSIGNMENT;')({
|
||||
ASSIGNMENT: path.node.expression
|
||||
}));
|
||||
}
|
||||
}
|
||||
})
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -507,3 +507,20 @@ test('should resolve .js import to .ts file in non-ESM mode', async ({ runInline
|
||||
expect(result.passed).toBe(1);
|
||||
expect(result.exitCode).toBe(0);
|
||||
});
|
||||
|
||||
test('should import export assignment from ts', async ({ runInlineTest }) => {
|
||||
const result = await runInlineTest({
|
||||
'a.test.ts': `
|
||||
const { test } = pwt;
|
||||
import number from './utils.js';
|
||||
test('pass', () => {
|
||||
expect(number).toBe(1);
|
||||
});
|
||||
`,
|
||||
'utils.ts': `
|
||||
export = 1;
|
||||
`
|
||||
});
|
||||
expect(result.passed).toBe(1);
|
||||
expect(result.exitCode).toBe(0);
|
||||
});
|
||||
|
Loading…
x
Reference in New Issue
Block a user