forked from reduxjs/redux-toolkit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest-esm.mjs
51 lines (43 loc) · 1.48 KB
/
test-esm.mjs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
// TODO This entire file doesn't work yet with RTK 1.9.3 master
import assert from 'node:assert'
import path from 'path'
import { importMetaResolve } from 'resolve-esm'
import { createSlice } from '@reduxjs/toolkit'
import { createApi as createApiPlain } from '@reduxjs/toolkit/query'
import { createApi as createApiReact } from '@reduxjs/toolkit/query/react'
console.log('Testing Node with ESM imports...')
function checkFunctionName(fn, name, category) {
console.log(`Checking ${category} '${name}' === '${fn.name}'`)
assert(
fn.name === name,
`${category} \`${name}\` did not import correctly (name: '${fn.name}')`,
)
}
const entries = [
[createSlice, 'createSlice', 'Core'],
[createApiPlain, 'baseCreateApi', 'RTKQ core'],
[createApiReact, 'baseCreateApi', 'RTKQ React'],
]
for (let [fn, name, category] of entries) {
try {
checkFunctionName(fn, name, category)
} catch (error) {
console.error(error)
}
}
const moduleNames = [
['@reduxjs/toolkit', 'dist/redux-toolkit.modern.mjs'],
['@reduxjs/toolkit/query', 'dist/query/rtk-query.modern.mjs'],
[
'@reduxjs/toolkit/query/react',
'dist/query/react/rtk-query-react.modern.mjs',
],
]
;(async () => {
for (let [moduleName, expectedFilename] of moduleNames) {
const modulePath = await importMetaResolve(moduleName)
const posixPath = modulePath.split(path.sep).join(path.posix.sep)
console.log(`Module: ${moduleName}, path: ${posixPath}`)
assert(posixPath.endsWith(expectedFilename))
}
})()