Skip to content

Commit

Permalink
Fix CI tests
Browse files Browse the repository at this point in the history
- 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.
  • Loading branch information
aryaemami59 committed Jun 24, 2024
1 parent 07614dd commit 9371a4c
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 10 deletions.
8 changes: 6 additions & 2 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,11 @@ jobs:
- name: Install build artifact
run: yarn workspace @reduxjs/toolkit add $(pwd)/package.tgz

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

- name: Run tests, against dist
env:
TEST_DIST: true
run: yarn test

test-types:
Expand Down Expand Up @@ -134,9 +136,11 @@ jobs:
- name: Show installed RTK versions
run: yarn info @reduxjs/toolkit

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

- name: Test types
env:
TEST_DIST: true
run: |
yarn tsc --version
yarn type-tests
Expand Down
50 changes: 42 additions & 8 deletions packages/toolkit/src/tests/configureStore.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,11 @@ describe('configureStore', async () => {
expect.any(Function),
)
expect(redux.applyMiddleware).toHaveBeenCalled()
expect(composeWithDevToolsSpy).toHaveBeenCalled() // @remap-prod-remove-line
if (process.env.TEST_DIST) {
expect(composeWithDevToolsSpy).not.toHaveBeenCalled()
} else {
expect(composeWithDevToolsSpy).toHaveBeenCalledTimes(2)
}
})
})

Expand All @@ -53,7 +57,11 @@ describe('configureStore', async () => {
expect(configureStore({ reducer })).toBeInstanceOf(Object)
expect(redux.combineReducers).toHaveBeenCalledWith(reducer)
expect(redux.applyMiddleware).toHaveBeenCalled()
expect(composeWithDevToolsSpy).toHaveBeenCalled() // @remap-prod-remove-line
if (process.env.TEST_DIST) {
expect(composeWithDevToolsSpy).not.toHaveBeenCalled()
} else {
expect(composeWithDevToolsSpy).toHaveBeenCalledOnce()
}
expect(redux.createStore).toHaveBeenCalledWith(
expect.any(Function),
undefined,
Expand All @@ -76,7 +84,11 @@ describe('configureStore', async () => {
configureStore({ middleware: () => new Tuple(), reducer }),
).toBeInstanceOf(Object)
expect(redux.applyMiddleware).toHaveBeenCalledWith()
expect(composeWithDevToolsSpy).toHaveBeenCalled() // @remap-prod-remove-line
if (process.env.TEST_DIST) {
expect(composeWithDevToolsSpy).not.toHaveBeenCalled()
} else {
expect(composeWithDevToolsSpy).toHaveBeenCalledOnce()
}
expect(redux.createStore).toHaveBeenCalledWith(
reducer,
undefined,
Expand Down Expand Up @@ -105,7 +117,11 @@ describe('configureStore', async () => {
expect.any(Function), // serializableCheck
expect.any(Function), // actionCreatorCheck
)
expect(composeWithDevToolsSpy).toHaveBeenCalled() // @remap-prod-remove-line
if (process.env.TEST_DIST) {
expect(composeWithDevToolsSpy).not.toHaveBeenCalled()
} else {
expect(composeWithDevToolsSpy).toHaveBeenCalledOnce()
}
expect(redux.createStore).toHaveBeenCalledWith(
reducer,
undefined,
Expand Down Expand Up @@ -142,7 +158,11 @@ describe('configureStore', async () => {
configureStore({ middleware: () => new Tuple(thank), reducer }),
).toBeInstanceOf(Object)
expect(redux.applyMiddleware).toHaveBeenCalledWith(thank)
expect(composeWithDevToolsSpy).toHaveBeenCalled() // @remap-prod-remove-line
if (process.env.TEST_DIST) {
expect(composeWithDevToolsSpy).not.toHaveBeenCalled()
} else {
expect(composeWithDevToolsSpy).toHaveBeenCalledOnce()
}
expect(redux.createStore).toHaveBeenCalledWith(
reducer,
undefined,
Expand Down Expand Up @@ -197,7 +217,13 @@ describe('configureStore', async () => {
Object,
)
expect(redux.applyMiddleware).toHaveBeenCalled()
expect(composeWithDevToolsSpy).toHaveBeenCalledWith(options) // @remap-prod-remove-line
if (process.env.TEST_DIST) {
expect(composeWithDevToolsSpy).not.toHaveBeenCalled()
} else {
expect(composeWithDevToolsSpy).toHaveBeenCalledOnce()

expect(composeWithDevToolsSpy).toHaveBeenLastCalledWith(options)
}
expect(redux.createStore).toHaveBeenCalledWith(
reducer,
undefined,
Expand All @@ -210,7 +236,11 @@ describe('configureStore', async () => {
it('calls createStore with preloadedState', () => {
expect(configureStore({ reducer })).toBeInstanceOf(Object)
expect(redux.applyMiddleware).toHaveBeenCalled()
expect(composeWithDevToolsSpy).toHaveBeenCalled() // @remap-prod-remove-line
if (process.env.TEST_DIST) {
expect(composeWithDevToolsSpy).not.toHaveBeenCalled()
} else {
expect(composeWithDevToolsSpy).toHaveBeenCalledOnce()
}
expect(redux.createStore).toHaveBeenCalledWith(
reducer,
undefined,
Expand Down Expand Up @@ -241,7 +271,11 @@ describe('configureStore', async () => {
}),
).toBeInstanceOf(Object)
expect(redux.applyMiddleware).toHaveBeenCalled()
expect(composeWithDevToolsSpy).toHaveBeenCalled() // @remap-prod-remove-line
if (process.env.TEST_DIST) {
expect(composeWithDevToolsSpy).not.toHaveBeenCalled()
} else {
expect(composeWithDevToolsSpy).toHaveBeenCalledOnce()
}
expect(redux.createStore).toHaveBeenCalledWith(
reducer,
undefined,
Expand Down
8 changes: 8 additions & 0 deletions packages/toolkit/vitest.config.mts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,14 @@ const __dirname = path.dirname(__filename)
export default defineConfig({
plugins: [tsconfigPaths({ root: __dirname })],
test: {
alias: process.env.TEST_DIST
? {
'@reduxjs/toolkit': new URL(
'node_modules/@reduxjs/toolkit',
import.meta.url,
).pathname,
}
: undefined,
globals: true,
environment: 'jsdom',
setupFiles: ['./vitest.setup.ts'],
Expand Down

0 comments on commit 9371a4c

Please sign in to comment.