Skip to content

Commit 9371a4c

Browse files
committed
Fix CI tests
- It seems like the new version of Vite much like Node.js allows packages to self-reference themselves, which became a problem considering how we were running the tests against the build artifact during CI.
1 parent 07614dd commit 9371a4c

File tree

3 files changed

+56
-10
lines changed

3 files changed

+56
-10
lines changed

.github/workflows/tests.yml

+6-2
Original file line numberDiff line numberDiff line change
@@ -92,9 +92,11 @@ jobs:
9292
- name: Install build artifact
9393
run: yarn workspace @reduxjs/toolkit add $(pwd)/package.tgz
9494

95-
- run: sed -i -e /@remap-prod-remove-line/d ./tsconfig.base.json ./vitest.config.mts ./src/tests/*.* ./src/query/tests/*.*
95+
- run: sed -i -e /@remap-prod-remove-line/d ./tsconfig.base.json
9696

9797
- name: Run tests, against dist
98+
env:
99+
TEST_DIST: true
98100
run: yarn test
99101

100102
test-types:
@@ -134,9 +136,11 @@ jobs:
134136
- name: Show installed RTK versions
135137
run: yarn info @reduxjs/toolkit
136138

137-
- run: sed -i -e /@remap-prod-remove-line/d ./tsconfig.base.json ./vitest.config.mts ./src/tests/*.* ./src/query/tests/*.*
139+
- run: sed -i -e /@remap-prod-remove-line/d ./tsconfig.base.json
138140

139141
- name: Test types
142+
env:
143+
TEST_DIST: true
140144
run: |
141145
yarn tsc --version
142146
yarn type-tests

packages/toolkit/src/tests/configureStore.test.ts

+42-8
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,11 @@ describe('configureStore', async () => {
3939
expect.any(Function),
4040
)
4141
expect(redux.applyMiddleware).toHaveBeenCalled()
42-
expect(composeWithDevToolsSpy).toHaveBeenCalled() // @remap-prod-remove-line
42+
if (process.env.TEST_DIST) {
43+
expect(composeWithDevToolsSpy).not.toHaveBeenCalled()
44+
} else {
45+
expect(composeWithDevToolsSpy).toHaveBeenCalledTimes(2)
46+
}
4347
})
4448
})
4549

@@ -53,7 +57,11 @@ describe('configureStore', async () => {
5357
expect(configureStore({ reducer })).toBeInstanceOf(Object)
5458
expect(redux.combineReducers).toHaveBeenCalledWith(reducer)
5559
expect(redux.applyMiddleware).toHaveBeenCalled()
56-
expect(composeWithDevToolsSpy).toHaveBeenCalled() // @remap-prod-remove-line
60+
if (process.env.TEST_DIST) {
61+
expect(composeWithDevToolsSpy).not.toHaveBeenCalled()
62+
} else {
63+
expect(composeWithDevToolsSpy).toHaveBeenCalledOnce()
64+
}
5765
expect(redux.createStore).toHaveBeenCalledWith(
5866
expect.any(Function),
5967
undefined,
@@ -76,7 +84,11 @@ describe('configureStore', async () => {
7684
configureStore({ middleware: () => new Tuple(), reducer }),
7785
).toBeInstanceOf(Object)
7886
expect(redux.applyMiddleware).toHaveBeenCalledWith()
79-
expect(composeWithDevToolsSpy).toHaveBeenCalled() // @remap-prod-remove-line
87+
if (process.env.TEST_DIST) {
88+
expect(composeWithDevToolsSpy).not.toHaveBeenCalled()
89+
} else {
90+
expect(composeWithDevToolsSpy).toHaveBeenCalledOnce()
91+
}
8092
expect(redux.createStore).toHaveBeenCalledWith(
8193
reducer,
8294
undefined,
@@ -105,7 +117,11 @@ describe('configureStore', async () => {
105117
expect.any(Function), // serializableCheck
106118
expect.any(Function), // actionCreatorCheck
107119
)
108-
expect(composeWithDevToolsSpy).toHaveBeenCalled() // @remap-prod-remove-line
120+
if (process.env.TEST_DIST) {
121+
expect(composeWithDevToolsSpy).not.toHaveBeenCalled()
122+
} else {
123+
expect(composeWithDevToolsSpy).toHaveBeenCalledOnce()
124+
}
109125
expect(redux.createStore).toHaveBeenCalledWith(
110126
reducer,
111127
undefined,
@@ -142,7 +158,11 @@ describe('configureStore', async () => {
142158
configureStore({ middleware: () => new Tuple(thank), reducer }),
143159
).toBeInstanceOf(Object)
144160
expect(redux.applyMiddleware).toHaveBeenCalledWith(thank)
145-
expect(composeWithDevToolsSpy).toHaveBeenCalled() // @remap-prod-remove-line
161+
if (process.env.TEST_DIST) {
162+
expect(composeWithDevToolsSpy).not.toHaveBeenCalled()
163+
} else {
164+
expect(composeWithDevToolsSpy).toHaveBeenCalledOnce()
165+
}
146166
expect(redux.createStore).toHaveBeenCalledWith(
147167
reducer,
148168
undefined,
@@ -197,7 +217,13 @@ describe('configureStore', async () => {
197217
Object,
198218
)
199219
expect(redux.applyMiddleware).toHaveBeenCalled()
200-
expect(composeWithDevToolsSpy).toHaveBeenCalledWith(options) // @remap-prod-remove-line
220+
if (process.env.TEST_DIST) {
221+
expect(composeWithDevToolsSpy).not.toHaveBeenCalled()
222+
} else {
223+
expect(composeWithDevToolsSpy).toHaveBeenCalledOnce()
224+
225+
expect(composeWithDevToolsSpy).toHaveBeenLastCalledWith(options)
226+
}
201227
expect(redux.createStore).toHaveBeenCalledWith(
202228
reducer,
203229
undefined,
@@ -210,7 +236,11 @@ describe('configureStore', async () => {
210236
it('calls createStore with preloadedState', () => {
211237
expect(configureStore({ reducer })).toBeInstanceOf(Object)
212238
expect(redux.applyMiddleware).toHaveBeenCalled()
213-
expect(composeWithDevToolsSpy).toHaveBeenCalled() // @remap-prod-remove-line
239+
if (process.env.TEST_DIST) {
240+
expect(composeWithDevToolsSpy).not.toHaveBeenCalled()
241+
} else {
242+
expect(composeWithDevToolsSpy).toHaveBeenCalledOnce()
243+
}
214244
expect(redux.createStore).toHaveBeenCalledWith(
215245
reducer,
216246
undefined,
@@ -241,7 +271,11 @@ describe('configureStore', async () => {
241271
}),
242272
).toBeInstanceOf(Object)
243273
expect(redux.applyMiddleware).toHaveBeenCalled()
244-
expect(composeWithDevToolsSpy).toHaveBeenCalled() // @remap-prod-remove-line
274+
if (process.env.TEST_DIST) {
275+
expect(composeWithDevToolsSpy).not.toHaveBeenCalled()
276+
} else {
277+
expect(composeWithDevToolsSpy).toHaveBeenCalledOnce()
278+
}
245279
expect(redux.createStore).toHaveBeenCalledWith(
246280
reducer,
247281
undefined,

packages/toolkit/vitest.config.mts

+8
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,14 @@ const __dirname = path.dirname(__filename)
1010
export default defineConfig({
1111
plugins: [tsconfigPaths({ root: __dirname })],
1212
test: {
13+
alias: process.env.TEST_DIST
14+
? {
15+
'@reduxjs/toolkit': new URL(
16+
'node_modules/@reduxjs/toolkit',
17+
import.meta.url,
18+
).pathname,
19+
}
20+
: undefined,
1321
globals: true,
1422
environment: 'jsdom',
1523
setupFiles: ['./vitest.setup.ts'],

0 commit comments

Comments
 (0)