Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions e2e/mock/fixtures/esModulesLinkingError/index.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { describe, expect, it, rs } from '@rstest/core';
// @ts-expect-error
import * as serviceAPI from './services';

rs.mock('./services', () => ({
value: 42,
}));

describe('Mock Module EsModulesLinkingError', () => {
it('should return the mocked value', () => {
expect(serviceAPI.value).toBe(42);
});
});
1 change: 1 addition & 0 deletions e2e/mock/fixtures/esModulesLinkingError/services/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const a = 42;
29 changes: 29 additions & 0 deletions e2e/mock/tests/esModulesLinkingError.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { dirname, join } from 'node:path';
import { fileURLToPath } from 'node:url';
import { describe, expect, it } from '@rstest/core';
import { runRstestCli } from '../../scripts';

const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);

describe('test EsModulesLinkingError', () => {
it('should not print EsModulesLinkingError', async () => {
const { cli, expectExecSuccess } = await runRstestCli({
command: 'rstest',
args: ['run'],
options: {
nodeOptions: {
cwd: join(__dirname, '../fixtures/esModulesLinkingError'),
},
},
});

await expectExecSuccess();

const logs = cli.stdout.split('\n').filter(Boolean);

expect(
logs.find((log) => log.match(/ESModulesLinkingError: export 'value'/)),
).toBeUndefined();
});
});
2 changes: 2 additions & 0 deletions packages/core/src/core/plugins/basic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,8 @@ export const pluginBasic: (context: RstestContext) => RsbuildPlugin = (
// Keep require.resolve expressions.
requireResolve: false,
...(config.module.parser.javascript || {}),
// suppress ESModulesLinkingError for exports that might be implemented in mock
exportsPresence: 'warn',
};

config.resolve ??= {};
Expand Down
10 changes: 5 additions & 5 deletions packages/core/tests/core/__snapshots__/rsbuild.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ exports[`prepareRsbuild > should generate rspack config correctly (jsdom) 1`] =
"module": {
"parser": {
"javascript": {
"exportsPresence": "error",
"exportsPresence": "warn",
"importDynamic": false,
"inlineConst": false,
"requireAsExpression": false,
Expand Down Expand Up @@ -555,7 +555,7 @@ exports[`prepareRsbuild > should generate rspack config correctly (node) 1`] = `
"module": {
"parser": {
"javascript": {
"exportsPresence": "error",
"exportsPresence": "warn",
"importDynamic": false,
"inlineConst": false,
"requireAsExpression": false,
Expand Down Expand Up @@ -1066,7 +1066,7 @@ exports[`prepareRsbuild > should generate rspack config correctly in watch mode
"module": {
"parser": {
"javascript": {
"exportsPresence": "error",
"exportsPresence": "warn",
"importDynamic": false,
"inlineConst": false,
"requireAsExpression": false,
Expand Down Expand Up @@ -1584,7 +1584,7 @@ exports[`prepareRsbuild > should generate rspack config correctly with projects
"module": {
"parser": {
"javascript": {
"exportsPresence": "error",
"exportsPresence": "warn",
"importDynamic": false,
"inlineConst": false,
"requireAsExpression": false,
Expand Down Expand Up @@ -2104,7 +2104,7 @@ exports[`prepareRsbuild > should generate rspack config correctly with projects
"module": {
"parser": {
"javascript": {
"exportsPresence": "error",
"exportsPresence": "warn",
"importDynamic": false,
"inlineConst": false,
"requireAsExpression": false,
Expand Down
Loading