Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GS-8167 Migrate from jest to vitest #258

Merged
merged 9 commits into from
Sep 20, 2024
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@
},
"env": {
"es2022": true,
"node": true,
"jest": true
"node": true
},
"rules": {
"import/extensions": [2, { "js": "always" }]
Expand Down
4 changes: 1 addition & 3 deletions .github/workflows/pull-request.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,7 @@ jobs:
prettier_command_prefix: yarn

- name: Test
run: yarn run jest --ci --reporters github-actions --reporters summary --coverage .
env:
NODE_OPTIONS: '--no-warnings --experimental-vm-modules'
run: yarn run test --reporter github-actions --reporter default --coverage
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion: Remove reporters configuration

github-actions is the default when running in CI and default is well, the default.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops, missed it.


- name: Report Coverage
uses: romeovs/lcov-reporter-action@2a28ec3e25fb7eae9cb537e9141603486f810d1a
Expand Down
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ node_modules/
# Build output
dist

# Jest
# Vitest
coverage

# Yarn stuff: https://yarnpkg.com/getting-started/qa#which-files-should-be-gitignored
Expand Down
20 changes: 6 additions & 14 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,28 +8,20 @@ Commands can be run from the root or scoped to specific directories/workspaces
# From the root:
# > yarn {cmd} [dir]
# Ex:
yarn jest
yarn jest packages/client
yarn test
yarn test packages/client

# From inside package directory
# > cd packages/{dir} && yarn run -T {cmd}
# Ex:
cd packages/client && yarn run -T jest
cd packages/client && yarn run -T test

# From any directory, specifying workspace
# > yarn workspace {workspace} run -T {cmd}
# > yarn workspace {workspace} run {cmd}
# Ex:
yarn workspace contexture-client run -T jest .
yarn workspace contexture-client run test .
```

#### Tests

Tests can be scoped via `jest --selectProjects {project}`. Refer to [jest's config](./jest.config.js) for project names.

> :warning: You need `NODE_OPTIONS=--experimental-vm-modules` in your environment for `jest` to [parse ESM](https://jestjs.io/docs/28.x/ecmascript-modules#differences-between-esm-and-commonjs). Optionally, use [direnv](https://direnv.net/) for local setup of environment variables.

Example test command for client watch mode:
`NODE_OPTIONS=--experimental-vm-modules yarn jest packages/client/src/index.test.js --watch --verbose=false`

Example test command for provider-elasticsearch watch mode:
`NODE_OPTIONS=--experimental-vm-modules yarn jest packages/provider-elasticsearch/test/index.test.js --watch --verbose=false`
Tests can be scoped via `vitest --project {project}`. Refer to [vitest's workspaces](./vitest.workspace.ts) for project names.
35 changes: 0 additions & 35 deletions jest.config.js

This file was deleted.

7 changes: 4 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,22 @@
"version": "yarn changeset version && yarn install --mode=update-lockfile",
"publish": "yarn foreach npm publish --tolerate-republish",
"postinstall": "yarn foreach run prepack",
"test": "NODE_NO_WARNINGS=1 NODE_OPTIONS=--experimental-vm-modules yarn jest ."
"test": "vitest"
},
"devDependencies": {
"@changesets/cli": "^2.26.0",
"@flex-development/toggle-pkg-type": "^1.0.1",
"@vitest/coverage-v8": "^2.1.1",
"danger": "^11.2.3",
"duti": "^0.15.2",
"esbuild": "^0.17.5",
"eslint": "^8.33.0",
"eslint-import-resolver-typescript": "^3.5.3",
"eslint-plugin-import": "^2.27.5",
"glob": "^8.1.0",
"jest": "^29.4.1",
"minimist": "^1.2.7",
"prettier": "^2.8.3"
"prettier": "^2.8.3",
"vitest": "^2.1.1"
},
"packageManager": "[email protected]"
}
2 changes: 1 addition & 1 deletion packages/client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
],
"scripts": {
"prepack": "node ../../scripts/esbuild.js --platform=browser",
"test": "NODE_NO_WARNINGS=1 NODE_OPTIONS=--experimental-vm-modules yarn run -T jest ."
"test": "yarn run -T test --project client"
},
"repository": {
"type": "git",
Expand Down
12 changes: 6 additions & 6 deletions packages/client/src/_mobx.test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// DO NOT RENAME THIS FILE... because we need it to run before the other tests...
// No, we don't know why. We're sorry. #hackathon

import { jest } from '@jest/globals'
import { vi, describe, expect, it } from 'vitest'
import { Tree } from './util/tree.js'
import F from 'futil'
import _ from 'lodash/fp.js'
Expand Down Expand Up @@ -49,10 +49,10 @@ describe('usage with mobx should generally work', () => {
{ key: 'filter', type: 'facet' },
],
}
let service = jest.fn(() => responseData)
let service = vi.fn(() => responseData)
let Tree = ContextureMobx({ service, debounce: 1 })(tree)

let reactor = jest.fn()
let reactor = vi.fn()

it('should generally mutate and have updated contexts', async () => {
let disposer = reaction(() => toJS(Tree.tree), reactor)
Expand Down Expand Up @@ -340,7 +340,7 @@ describe('usage with mobx should generally work', () => {
})
it('should support observing disableAutoUpdate', () => {
service.mockClear()
let reactor = jest.fn()
let reactor = vi.fn()
let tree = ContextureMobx({ service, debounce: 1 })({
key: 'root',
join: 'and',
Expand All @@ -358,8 +358,8 @@ describe('usage with mobx should generally work', () => {
expect(reactor).toHaveBeenCalledTimes(1)
})
it('should react to group fns', async () => {
let service = jest.fn(mockService({}))
let reactor = jest.fn()
let service = vi.fn(mockService({}))
let reactor = vi.fn()
let tree = ContextureMobx(
{ service, debounce: 1 },
{
Expand Down
Loading
Loading