Skip to content

Commit f25cf7b

Browse files
committed
Add Node CI examples
1 parent b57fd8c commit f25cf7b

File tree

11 files changed

+820
-1
lines changed

11 files changed

+820
-1
lines changed

.github/workflows/tests.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ jobs:
149149
fail-fast: false
150150
matrix:
151151
node: ['16.x']
152-
example: ['cra4', 'cra5', 'next', 'vite']
152+
example: ['cra4', 'cra5', 'next', 'vite', 'node-standard', 'node-esm']
153153
defaults:
154154
run:
155155
working-directory: ./examples/publish-ci/${{ matrix.example }}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
2+
3+
# dependencies
4+
/node_modules
5+
/.pnp
6+
.pnp.js
7+
8+
# testing
9+
/coverage
10+
11+
# production
12+
/build
13+
14+
# misc
15+
.DS_Store
16+
.env.local
17+
.env.development.local
18+
.env.test.local
19+
.env.production.local
20+
21+
npm-debug.log*
22+
yarn-debug.log*
23+
yarn-error.log*
24+
25+
typesversions
26+
.cache
27+
.yarnrc
28+
.yarn/*
29+
!.yarn/patches
30+
!.yarn/releases
31+
!.yarn/plugins
32+
!.yarn/sdks
33+
!.yarn/versions
34+
.pnp.*
35+
*.tgz
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
"name": "dual-module-test",
3+
"version": "1.0.0",
4+
"license": "MIT",
5+
"type": "module",
6+
"scripts": {
7+
"build": "echo Done",
8+
"test": "node test-cjs.cjs"
9+
},
10+
"dependencies": {
11+
"@reduxjs/toolkit": "^1.9.3",
12+
"react": "^18.2.0",
13+
"react-dom": "^18.2.0",
14+
"react-redux": "^8.0.5"
15+
},
16+
"devDependencies": {
17+
"resolve-esm": "^1.4.0"
18+
}
19+
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
const assert = require('node:assert')
2+
const path = require('path')
3+
4+
const { createSlice } = require('@reduxjs/toolkit')
5+
const { createApi: createApiPlain } = require('@reduxjs/toolkit/query')
6+
const { createApi: createApiReact } = require('@reduxjs/toolkit/query/react')
7+
8+
console.log('Testing Node with CJS imports...')
9+
10+
function checkFunctionName(fn, name, category) {
11+
console.log(`Checking ${category} '${name}' === '${fn.name}'`)
12+
assert(
13+
fn.name === name,
14+
`${category} \`${name}\` did not import correctly (name: '${fn.name}')`
15+
)
16+
}
17+
18+
const entries = [
19+
[createSlice, 'createSlice', 'Core'],
20+
[createApiPlain, 'baseCreateApi', 'RTKQ core'],
21+
[createApiReact, 'baseCreateApi', 'RTKQ React'],
22+
]
23+
24+
for (let [fn, name, category] of entries) {
25+
try {
26+
checkFunctionName(fn, name, category)
27+
} catch (error) {
28+
console.error(error)
29+
}
30+
}
31+
32+
const moduleNames = [
33+
['@reduxjs/toolkit', 'dist/index.js'],
34+
['@reduxjs/toolkit/query', 'dist/query/index.js'],
35+
['@reduxjs/toolkit/query/react', 'dist/query/react/index.js'],
36+
]
37+
38+
for (let [moduleName, expectedFilename] of moduleNames) {
39+
const modulePath = require.resolve(moduleName)
40+
const posixPath = modulePath.split(path.sep).join(path.posix.sep)
41+
console.log(`Module: ${moduleName}, path: ${posixPath}`)
42+
assert(posixPath.endsWith(expectedFilename))
43+
}
44+
45+
console.log('CJS test succeeded')
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
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

Comments
 (0)