Skip to content

Commit

Permalink
test: failing test for #38
Browse files Browse the repository at this point in the history
  • Loading branch information
privatenumber committed Jun 21, 2022
1 parent e733726 commit aaa330c
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 0 deletions.
2 changes: 2 additions & 0 deletions tests/fixtures/node_modules/package-commonjs/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions tests/fixtures/node_modules/package-commonjs/package.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions tests/fixtures/node_modules/package-commonjs/ts.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 16 additions & 0 deletions tests/specs/javascript/dependencies.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,22 @@ import type { NodeApis } from '../../utils/tsx';

export default testSuite(async ({ describe }, node: NodeApis) => {
describe('Dependencies', ({ describe }) => {
describe('commonjs dependency', ({ test }) => {
const output = '{"default":"default export","namedExport":"named export"}';

test('Import', async () => {
const nodeProcess = await node.import('package-commonjs');
expect(nodeProcess.stdout).toBe(output);
expect(nodeProcess.stderr).toBe('');
});

test('Import static', async () => {
const nodeProcess = await node.importStatic('package-commonjs');
expect(nodeProcess.stdout).toBe(output);
expect(nodeProcess.stderr).toBe('');
});
});

describe('module dependency', ({ test }) => {
const output = '{"default":"default export","namedExport":"named export"}';

Expand Down
32 changes: 32 additions & 0 deletions tests/utils/tsx.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import fs from 'fs/promises';
import path from 'path';
import { fileURLToPath } from 'url';
import { execaNode } from 'execa';
Expand Down Expand Up @@ -28,6 +29,8 @@ export const tsx = (
},
);

let id = 0;

export async function createNode(
nodeVersion: string,
fixturePath: string,
Expand Down Expand Up @@ -69,6 +72,35 @@ export async function createNode(
cwd: fixturePath,
});
},
async importStatic(
filePath: string,
options?: {
extension?: string;
},
) {
id += 1;
const importerFileName = `static-import-file.${id}.${options?.extension || 'js'}`;
const importerFilePath = path.join(fixturePath, importerFileName);
await fs.writeFile(
importerFilePath,
`
import * as value from '${filePath}';
console.log(JSON.stringify(value));
`,
);

const nodeProcess = await tsx({
args: [
importerFileName,
],
nodePath: node.path,
cwd: fixturePath,
});

await fs.rm(importerFilePath);

return nodeProcess;
},
require(
filePath: string,
options?: {
Expand Down

0 comments on commit aaa330c

Please sign in to comment.