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