Skip to content

Commit aaa330c

Browse files
committed
test: failing test for #38
1 parent e733726 commit aaa330c

File tree

5 files changed

+56
-0
lines changed

5 files changed

+56
-0
lines changed

tests/fixtures/node_modules/package-commonjs/index.js

+2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/fixtures/node_modules/package-commonjs/package.json

+4
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/fixtures/node_modules/package-commonjs/ts.ts

+2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/specs/javascript/dependencies.ts

+16
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,22 @@ import type { NodeApis } from '../../utils/tsx';
33

44
export default testSuite(async ({ describe }, node: NodeApis) => {
55
describe('Dependencies', ({ describe }) => {
6+
describe('commonjs dependency', ({ test }) => {
7+
const output = '{"default":"default export","namedExport":"named export"}';
8+
9+
test('Import', async () => {
10+
const nodeProcess = await node.import('package-commonjs');
11+
expect(nodeProcess.stdout).toBe(output);
12+
expect(nodeProcess.stderr).toBe('');
13+
});
14+
15+
test('Import static', async () => {
16+
const nodeProcess = await node.importStatic('package-commonjs');
17+
expect(nodeProcess.stdout).toBe(output);
18+
expect(nodeProcess.stderr).toBe('');
19+
});
20+
});
21+
622
describe('module dependency', ({ test }) => {
723
const output = '{"default":"default export","namedExport":"named export"}';
824

tests/utils/tsx.ts

+32
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import fs from 'fs/promises';
12
import path from 'path';
23
import { fileURLToPath } from 'url';
34
import { execaNode } from 'execa';
@@ -28,6 +29,8 @@ export const tsx = (
2829
},
2930
);
3031

32+
let id = 0;
33+
3134
export async function createNode(
3235
nodeVersion: string,
3336
fixturePath: string,
@@ -69,6 +72,35 @@ export async function createNode(
6972
cwd: fixturePath,
7073
});
7174
},
75+
async importStatic(
76+
filePath: string,
77+
options?: {
78+
extension?: string;
79+
},
80+
) {
81+
id += 1;
82+
const importerFileName = `static-import-file.${id}.${options?.extension || 'js'}`;
83+
const importerFilePath = path.join(fixturePath, importerFileName);
84+
await fs.writeFile(
85+
importerFilePath,
86+
`
87+
import * as value from '${filePath}';
88+
console.log(JSON.stringify(value));
89+
`,
90+
);
91+
92+
const nodeProcess = await tsx({
93+
args: [
94+
importerFileName,
95+
],
96+
nodePath: node.path,
97+
cwd: fixturePath,
98+
});
99+
100+
await fs.rm(importerFilePath);
101+
102+
return nodeProcess;
103+
},
72104
require(
73105
filePath: string,
74106
options?: {

0 commit comments

Comments
 (0)