Skip to content

Commit c0d6b17

Browse files
authored
chore(test): use t.mock.module for mocking (nodejs#7660)
chore(test): use `t.module.mock` for mocking
1 parent e2cf169 commit c0d6b17

File tree

6 files changed

+29
-65
lines changed

6 files changed

+29
-65
lines changed

apps/site/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
"lint": "turbo run lint:md lint:snippets lint:js lint:css",
1717
"lint:fix": "turbo run lint:md lint:js lint:css --no-cache -- --fix",
1818
"sync-orama": "node ./scripts/orama-search/sync-orama-cloud.mjs",
19-
"test:unit": "cross-env NODE_NO_WARNINGS=1 node --experimental-test-coverage --test-coverage-exclude=**/*.test.* --experimental-test-module-mocks --enable-source-maps --import=global-jsdom/register --import=tsx --import=tests/setup.mjs --test **/*.test.*",
19+
"test:unit": "cross-env NODE_NO_WARNINGS=1 node --experimental-test-coverage --test-coverage-exclude=**/*.test.* --experimental-test-module-mocks --enable-source-maps --import=global-jsdom/register --import=tsx --import=tests/setup.jsx --test **/*.test.*",
2020
"test:unit:watch": "cross-env NODE_OPTIONS=\"--watch\" npm run test:unit",
2121
"test": "turbo test:unit"
2222
},

apps/site/tests/loader.mjs

Lines changed: 0 additions & 37 deletions
This file was deleted.

apps/site/tests/mocks/next-intl.jsx

Lines changed: 0 additions & 16 deletions
This file was deleted.

apps/site/tests/mocks/next-router.mjs

Lines changed: 0 additions & 6 deletions
This file was deleted.

apps/site/tests/setup.jsx

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// We import this file before the root setup.mjs, so React is not automatically imported
2+
import * as React from 'react';
3+
4+
import { mock } from 'node:test';
5+
6+
import '../../../tests/setup.mjs';
7+
8+
mock.module('next-intl', {
9+
namedExports: {
10+
useTranslations: () => key => key,
11+
12+
useFormatter: () => {
13+
const formatWith = format => new Intl.DateTimeFormat('en-US', format);
14+
return {
15+
date: (date, format) => formatWith(format).format(date),
16+
dateTime: (date, format) => formatWith(format).format(date),
17+
};
18+
},
19+
},
20+
});
21+
22+
mock.module('next-intl/navigation', {
23+
namedExports: {
24+
createNavigation: () => ({
25+
Link: props => <a {...props} onClick={e => e.preventDefault()} />,
26+
}),
27+
},
28+
});

apps/site/tests/setup.mjs

Lines changed: 0 additions & 5 deletions
This file was deleted.

0 commit comments

Comments
 (0)