Skip to content

Commit

Permalink
fix vitest
Browse files Browse the repository at this point in the history
  • Loading branch information
fi3ework committed Dec 16, 2024
1 parent 16d257e commit 124441d
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 27 deletions.
3 changes: 0 additions & 3 deletions tests/integration/redirect/__fixtures__/src/bar/index.ts

This file was deleted.

1 change: 0 additions & 1 deletion tests/integration/redirect/__fixtures__/src/constant.ts

This file was deleted.

1 change: 0 additions & 1 deletion tests/integration/redirect/__fixtures__/src/foo.ts

This file was deleted.

10 changes: 0 additions & 10 deletions tests/integration/redirect/__fixtures__/src/index.ts

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,18 +1,24 @@
import path from 'node:path';
import { buildAndGetResults, queryContent } from 'test-helper';
import { beforeAll, expect, test } from 'vitest';

let contents: Awaited<ReturnType<typeof buildAndGetResults>>['contents'];

beforeAll(async () => {
const fixturePath = __dirname;
const fixturePath = path.resolve(__dirname, './js');
contents = (await buildAndGetResults({ fixturePath })).contents;
});

test('redirect.js default', async () => {
const { content: indexContent, path: indexPath } = queryContent(
const { content: indexContent, path: indexEsmPath } = queryContent(
contents.esm0!,
/esm\/index\.js/,
);
const { path: indexCjsPath } = await queryContent(
contents.cjs0!,
/cjs\/index\.cjs/,
);

expect(indexContent).toMatchInlineSnapshot(`
"import * as __WEBPACK_EXTERNAL_MODULE_lodash__ from "lodash";
import * as __WEBPACK_EXTERNAL_MODULE__bar_index_js__ from "./bar/index.js";
Expand All @@ -22,16 +28,19 @@ test('redirect.js default', async () => {
"
`);

expect((await import(indexPath)).default).toMatchInlineSnapshot(
`"FOOBAR1FOOBAR1"`,
);
const esmResult = await import(indexEsmPath);
const cjsResult = await import(indexCjsPath);

expect(esmResult.default).toEqual(cjsResult.default);
expect(esmResult.default).toMatchInlineSnapshot(`"FOOBAR1FOOBAR1"`);
});

test('redirect.js.path false', async () => {
const { content: indexContent } = queryContent(
contents.esm1!,
/esm\/index\.js/,
);

expect(indexContent).toMatchInlineSnapshot(`
"import * as __WEBPACK_EXTERNAL_MODULE_lodash__ from "lodash";
import * as __WEBPACK_EXTERNAL_MODULE__bar_js__ from "@/bar.js";
Expand All @@ -45,10 +54,15 @@ test('redirect.js.path false', async () => {
});

test('redirect.js.path with user override externals', async () => {
const { content: indexContent, path: indexPath } = queryContent(
const { content: indexContent, path: indexEsmPath } = queryContent(
contents.esm2!,
/esm\/index\.js/,
);
const { path: indexCjsPath } = await queryContent(
contents.cjs2!,
/cjs\/index\.cjs/,
);

expect(indexContent).toMatchInlineSnapshot(`
"import * as __WEBPACK_EXTERNAL_MODULE_lodash__ from "lodash";
import * as __WEBPACK_EXTERNAL_MODULE__others_bar_index_js__ from "./others/bar/index.js";
Expand All @@ -60,9 +74,11 @@ test('redirect.js.path with user override externals', async () => {
"
`);

expect((await import(indexPath)).default).toMatchInlineSnapshot(
`"FOOBAR1OTHERFOOOTHERBAR2"`, // cspell:disable-line
);
const esmResult = await import(indexEsmPath);
const cjsResult = await import(indexCjsPath);

expect(esmResult.default).toEqual(cjsResult.default);
expect(esmResult.default).toMatchInlineSnapshot(`"FOOBAR1OTHERFOOOTHERBAR2"`); // cspell:disable-line
});

test('redirect.js.extension: false', async () => {
Expand Down
4 changes: 2 additions & 2 deletions tests/integration/redirect/js/rslib.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,8 @@ export default defineConfig({
root: 'dist/js-path-externals-override/cjs',
},
externals: {
'@/foo': './src/others/foo',
'@/bar': './src/others/bar',
'@/foo': './others/foo.cjs',
'@/bar': './others/bar/index.cjs',
},
},
}),
Expand Down
2 changes: 1 addition & 1 deletion tests/integration/redirect/js/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ import lodash from 'lodash';
import { bar as bar2 } from '@/bar';
import { foo as foo2 } from '@/foo';
import { bar } from './bar';
import { foo } from './foo.ts';
import { foo } from './foo';

export default lodash.toUpper(foo + bar + foo2 + bar2);

0 comments on commit 124441d

Please sign in to comment.