Skip to content

Commit 68dfa29

Browse files
leeyi45RichDom2185
andauthored
Migrate to Vitest (#1815)
* Upgrade TS to 5.8 * Remove deprecated tsconfig option * Remove duplicate properties * Upgrade TS to v5.9 * Add types for mathjs * Fix some type errors * Update tsconfig * Fix more type errors * Fix remaining errors * Update GitHub workflows * Fix type error * Update scm-slang to latest * Add newline to EOF * Fix cse-machine types and utils to use fewer type assertions * Migrate to vitest tests * Migrate tests to vitest * Relocate base error files and types * Get modules tests working * run format * Sort tsconfig compiler options * Update eslint packages to match typescript version * Small linting change * Use function names instead of strings for describe blocks * Include scripts in linting * Move tests and replace describe titles with functions * Add type modifiers and reformat tests * Simplify isEnvDependent code * Instruct tsc to ignore py-slang's tests during build * Move walkers to be under utils/ast * Update tests failing due to timeout * Update cse-machine typings * Incorporate import assertions into docs importer * Add context property to error result * Update test timeout and add no-restricted-import rule for commander imports * Update snapshots * Run format * Update snapshots again.... * Run format * Change to use the test.each * Disable the svmc snapshot test cause it doesn't work * Add a new test for properties when loading modules * Run format * Convert stdlib parser to use nodetypetonode helper type * A working version of the statementSeqTransform * More compact version of seq transform * Remove unnecessary type assertions * Clean up some documentation bits and pieces * Use type imports for tracer * Swap the list library to use generics * Fix some error messages and tests * Fix list tests * Run format * Update stream library and tests * Running format * Add some documentation for the scripts * Remove unnecessary packages * Remove even more unnecessary types * Add better typings for autocomplete.mjs * Add type modifiers to imports * Merge with the main branch * Update to VItest 4 * Simplify Vitest coverage configuration * Update typing for vm * Update some other miscellanous tests * Remove these error causing snapshots * Run format * Update quotes * Update actions/setup-node to v6 * Fix imports post-merge * Use Node 22 to fix local issues * Fix test timeouts * Fix test timeouts again * Deduplicate dependencies * Bump TS to 5.9.3 * Bump lint deps to latest * Revert "Deduplicate dependencies" This reverts commit 4390454. * Remove old Jest snapshot * Revert "Remove old Jest snapshot" This reverts commit 2f072b3. --------- Co-authored-by: Richard Dominick <34370238+RichDom2185@users.noreply.github.com>
1 parent 87a9c94 commit 68dfa29

File tree

247 files changed

+19376
-17869
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

247 files changed

+19376
-17869
lines changed

.babelrc

Lines changed: 0 additions & 3 deletions
This file was deleted.

.editorconfig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
[*]
2-
end_of_line = lf
2+
end_of_line = lf

.github/workflows/deploy-docs.yml

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@ jobs:
88
runs-on: ubuntu-latest
99
steps:
1010
- name: Checkout repository
11-
uses: actions/checkout@v4
11+
uses: actions/checkout@v5
12+
with:
13+
submodules: recursive
1214
- name: Install dependencies (apt)
1315
run: |
1416
sudo apt-get update && \
@@ -19,9 +21,9 @@ jobs:
1921
- name: Enable corepack for Yarn
2022
run: corepack enable
2123
- name: Use Node.js
22-
uses: actions/setup-node@v4
24+
uses: actions/setup-node@v6
2325
with:
24-
node-version: 20
26+
node-version: 22
2527
cache: yarn
2628
- name: Install yarn dependencies
2729
run: yarn install --immutable

.github/workflows/nodejs.yml

Lines changed: 38 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -15,41 +15,41 @@ jobs:
1515
build:
1616
runs-on: ubuntu-latest
1717
steps:
18-
- name: Checkout repository
19-
uses: actions/checkout@v4
20-
with:
21-
submodules: recursive
22-
- name: Check for package-lock.json
23-
run: |
24-
if [ -e package-lock.json ]; then
25-
echo "package-lock.json found; please do not use NPM! This project uses Yarn!"
26-
exit 1
27-
fi
28-
exit 0
29-
- name: Install dependencies (apt)
30-
run: |
31-
sudo apt-get update && \
32-
sudo apt-get install -y --no-install-recommends \
33-
texlive texlive-fonts-extra texlive-lang-cjk latexmk latex-cjk-all
34-
# Has to be run before actions/setup-node.
35-
# See: https://github.com/actions/setup-node/issues/480
36-
- name: Enable corepack for Yarn
37-
run: corepack enable
38-
- name: Setup Node
39-
uses: actions/setup-node@v4
40-
with:
41-
node-version: 20
42-
cache: yarn
43-
- run: yarn install --immutable
44-
- run: yarn build
45-
- run: yarn format:ci
46-
- run: yarn eslint
47-
- run: yarn test-coverage
48-
env:
49-
CI: true
50-
- name: Check that docs build
51-
run: yarn jsdoc prepare
52-
- name: Coveralls
53-
uses: coverallsapp/github-action@master
54-
with:
55-
github-token: ${{ secrets.GITHUB_TOKEN }}
18+
- name: Checkout repository
19+
uses: actions/checkout@v5
20+
with:
21+
submodules: recursive
22+
- name: Check for package-lock.json
23+
run: |
24+
if [ -e package-lock.json ]; then
25+
echo "package-lock.json found; please do not use NPM! This project uses Yarn!"
26+
exit 1
27+
fi
28+
exit 0
29+
- name: Install dependencies (apt)
30+
run: |
31+
sudo apt-get update && \
32+
sudo apt-get install -y --no-install-recommends \
33+
texlive texlive-fonts-extra texlive-lang-cjk latexmk latex-cjk-all
34+
# Has to be run before actions/setup-node.
35+
# See: https://github.com/actions/setup-node/issues/480
36+
- name: Enable corepack for Yarn
37+
run: corepack enable
38+
- name: Setup Node
39+
uses: actions/setup-node@v6
40+
with:
41+
node-version: 22
42+
cache: yarn
43+
- run: yarn install --immutable
44+
- run: yarn build
45+
- run: yarn format:ci
46+
- run: yarn eslint
47+
- run: yarn test-coverage
48+
env:
49+
CI: true
50+
- name: Check that docs build
51+
run: yarn jsdoc prepare
52+
- name: Coveralls
53+
uses: coverallsapp/github-action@master
54+
with:
55+
github-token: ${{ secrets.GITHUB_TOKEN }}

.gitignore

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ coverage/
1717

1818
.vscode/
1919
*.tsbuildinfo
20-
test-report.html
20+
test-report
2121

2222
# yarn files
2323

@@ -27,4 +27,4 @@ test-report.html
2727
!.yarn/releases
2828
!.yarn/sdks
2929
!.yarn/versions
30-
yarn-error.log
30+
yarn-error.log

.node-version

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
20.11.0
1+
22.17.0

.prettierignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
/src/alt-langs/
22
/src/py-slang/
3-
/src/**/__tests__/**/__snapshots__
3+
/src/**/__tests__/**/__snapshots__

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,10 @@ Open-source implementations of the programming language _Source_. Source is a se
2020

2121
## Prerequisites
2222

23-
- NodeJS v20
23+
- NodeJS v22
2424
- Python: On MacBook Pro with chip Apple M1 Pro, use python 3.10.12. Here is [the correct way to set Python 3 as default on a Mac](https://opensource.com/article/19/5/python-3-default-mac).
2525
- yarn: use the version specified in `package.json`. On macos, you may need to run `corepack enable`.
26+
2627
## Usage
2728

2829
To build,

eslint.config.mjs

Lines changed: 50 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
// @ts-check
22

3+
import vitestPlugin from '@vitest/eslint-plugin'
34
import tseslint from 'typescript-eslint'
45
import globals from 'globals'
56
import * as importPlugin from 'eslint-plugin-import'
@@ -11,45 +12,68 @@ export default tseslint.config(
1112
},
1213
...tseslint.configs.recommended,
1314
{
14-
files: ['**/*.ts*', 'scripts/*.mjs'],
1515
languageOptions: {
1616
globals: {
1717
...globals.node,
1818
...globals.es2016,
1919
...globals.browser
2020
},
21-
parser: tseslint.parser,
22-
parserOptions: {
23-
project: './tsconfig.json'
24-
}
2521
},
2622
plugins: {
27-
'@typescript-eslint': tseslint.plugin,
2823
import: importPlugin
2924
},
3025
rules: {
26+
'import/first': 'warn',
27+
'import/newline-after-import': 'warn',
3128
'import/no-duplicates': ['warn', { 'prefer-inline': true }],
3229
'import/order': 'warn',
33-
'@typescript-eslint/no-base-to-string': 'off', // TODO: Remove
34-
'prefer-const': 'off', // TODO: Remove
30+
3531
'no-constant-condition': ['warn', { checkLoops: false }],
32+
'no-restricted-imports': [
33+
'error',
34+
{
35+
paths: [{
36+
name: 'commander',
37+
message: 'Import from @commander-js/extra-typings instead'
38+
}]
39+
}
40+
],
3641
'no-var': 'off', // TODO: Remove
42+
'object-shorthand': ['warn', 'properties'],
43+
'prefer-const': 'off', // TODO: Remove
44+
'prefer-rest-params': 'off',
45+
}
46+
},
47+
{
48+
files: ['**/*.ts*'],
49+
languageOptions: {
50+
parser: tseslint.parser,
51+
parserOptions: {
52+
project: './tsconfig.json'
53+
}
54+
},
55+
plugins: {
56+
'@typescript-eslint': tseslint.plugin,
57+
},
58+
rules: {
3759
'@typescript-eslint/ban-ts-comment': 'warn',
3860
'@typescript-eslint/ban-types': 'off',
3961
'@typescript-eslint/camelcase': 'off',
4062
'@typescript-eslint/explicit-function-return-type': 'off',
4163
'@typescript-eslint/explicit-module-boundary-types': 'off',
4264
'@typescript-eslint/interface-name-prefix': 'off',
65+
'@typescript-eslint/no-base-to-string': 'off', // TODO: Remove
4366
'@typescript-eslint/no-duplicate-type-constituents': 'off',
4467
'@typescript-eslint/no-empty-function': 'off',
4568
'@typescript-eslint/no-explicit-any': 'off',
4669
'@typescript-eslint/no-floating-promises': 'off',
4770
'@typescript-eslint/no-implied-eval': 'off',
71+
'@typescript-eslint/no-import-type-side-effects': 'error',
4872
'@typescript-eslint/no-inferrable-types': 'off',
4973
'@typescript-eslint/no-non-null-asserted-optional-chain': 'off',
5074
'@typescript-eslint/no-non-null-assertion': 'off',
5175
'@typescript-eslint/no-redundant-type-constituents': 'off',
52-
'@typescript-eslint/no-unnecessary-type-assertion': 'off',
76+
'@typescript-eslint/no-unnecessary-type-assertion': 'error',
5377
'@typescript-eslint/no-unsafe-argument': 'off',
5478
'@typescript-eslint/no-unsafe-assignment': 'off',
5579
'@typescript-eslint/no-unsafe-call': 'off',
@@ -62,12 +86,27 @@ export default tseslint.config(
6286
'@typescript-eslint/require-await': 'error',
6387
'@typescript-eslint/restrict-plus-operands': 'off',
6488
'@typescript-eslint/restrict-template-expressions': 'off',
89+
'@typescript-eslint/return-await': ['error', 'in-try-catch'],
6590
'@typescript-eslint/unbound-method': 'off',
66-
'prefer-rest-params': 'off'
6791
}
6892
},
6993
{
70-
files: ['**/*.js', 'src/repl/*.ts'],
94+
extends: [vitestPlugin.configs.recommended],
95+
files: ['**/__tests__/**/*.test.ts'],
96+
plugins: {
97+
vitest: vitestPlugin
98+
},
99+
rules: {
100+
'no-empty-pattern': 'off',
101+
'vitest/expect-expect': 'off', // TODO turn this back on
102+
'vitest/no-focused-tests': ['warn', { fixable: false }],
103+
'vitest/prefer-describe-function-title': 'warn',
104+
'vitest/valid-describe-callback': 'off',
105+
'vitest/valid-title': 'off',
106+
}
107+
},
108+
{
109+
files: ['**/*.js'],
71110
rules: {
72111
'@typescript-eslint/no-require-imports': 'off'
73112
}

package.json

Lines changed: 15 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -30,60 +30,53 @@
3030
"bin": "dist/repl/index.js",
3131
"dependencies": {
3232
"@babel/parser": "^7.19.4",
33-
"@commander-js/extra-typings": "^12.0.1",
34-
"@joeychenofficial/alt-ergo-modified": "^2.4.0",
33+
"@commander-js/extra-typings": "^14.0.0",
3534
"@ts-morph/bootstrap": "^0.18.0",
36-
"@types/estree": "^1.0.5",
3735
"acorn": "^8.8.2",
3836
"acorn-class-fields": "^1.0.0",
3937
"acorn-loose": "^8.0.0",
4038
"acorn-walk": "^8.0.0",
4139
"astring": "^1.4.3",
42-
"commander": "^12.0.0",
40+
"commander": "^14.0.0",
4341
"js-base64": "^3.7.5",
4442
"lodash": "^4.17.21",
4543
"source-map": "0.7.6"
4644
},
4745
"scripts": {
4846
"build": "yarn docs && yarn build:slang",
4947
"build:slang": "tsc --project tsconfig.prod.json",
50-
"eslint": "eslint src",
48+
"eslint": "eslint --concurrency=auto src scripts",
5149
"format": "prettier --write \"src/**/*.{ts,tsx}\"",
5250
"format:ci": "prettier --list-different \"src/**/*.{ts,tsx}\"",
53-
"test": "node ./scripts/run_jest.mjs",
51+
"test": "vitest",
5452
"test-coverage": "yarn test --coverage",
5553
"docs": "node ./scripts/docs.mjs docs",
5654
"jsdoc": "node ./scripts/docs.mjs",
5755
"autocomplete": "node ./scripts/docs.mjs autocomplete",
5856
"build_sicp_package": "yarn build && node ./scripts/build_sicp_package.mjs",
5957
"publish_sicp_package": "./scripts/publish_sicp_package.sh",
60-
"benchmark": "node ./scripts/run_jest.mjs --runInBand --testPathPattern='.*benchmark.*' --testPathIgnorePatterns='/dist/'",
58+
"benchmark": "vitest benchmark",
6159
"prepare": "husky"
6260
},
6361
"devDependencies": {
64-
"@babel/core": "^7.26.10",
65-
"@babel/preset-env": "^7.23.2",
66-
"@types/babel__core": "^7",
67-
"@types/jest": "^29.0.0",
62+
"@types/estree": "^1.0.5",
6863
"@types/lodash": "^4.14.202",
6964
"@types/node": "^20.0.0",
70-
"@types/offscreencanvas": "^2019.7.0",
65+
"@vitest/coverage-v8": "^4.0.4",
66+
"@vitest/eslint-plugin": "^1.3.4",
67+
"@vitest/ui": "^4.0.4",
7168
"ace-builds": "~1.17.0",
7269
"coveralls": "^3.1.0",
73-
"escodegen": "^2.0.0",
74-
"eslint": "^9.0.0",
75-
"eslint-plugin-import": "^2.29.1",
70+
"eslint": "^9.39.1",
71+
"eslint-plugin-import": "^2.32.0",
7672
"globals": "^16.0.0",
7773
"husky": "^9.0.0",
78-
"jest": "^29.0.0",
79-
"jest-environment-jsdom": "^29.0.0",
80-
"jest-html-reporter": "^3.2.0",
8174
"jsdoc": "3.6.11",
8275
"jsdom": "^19.0.0",
8376
"prettier": "^3.6.2",
84-
"ts-jest": "^29.0.0",
85-
"typescript": "^4.0.3",
86-
"typescript-eslint": "^8.8.1"
77+
"typescript": "^5.9.3",
78+
"typescript-eslint": "^8.46.3",
79+
"vitest": "^4.0.4"
8780
},
8881
"devEngines": {
8982
"packageManager": {
@@ -92,47 +85,5 @@
9285
"onFail": "error"
9386
}
9487
},
95-
"packageManager": "yarn@4.6.0",
96-
"jest": {
97-
"snapshotFormat": {
98-
"escapeString": true,
99-
"printBasicPrototype": true
100-
},
101-
"moduleFileExtensions": [
102-
"ts",
103-
"js"
104-
],
105-
"transform": {
106-
"\\.ts$": "ts-jest",
107-
"\\.js$": "babel-jest"
108-
},
109-
"testEnvironment": "jsdom",
110-
"testRegex": "/__tests__/.*\\.ts$",
111-
"testPathIgnorePatterns": [
112-
"/dist/",
113-
"/src/alt-langs/scheme/scm-slang",
114-
".*benchmark.*",
115-
"/__tests__/(.*/)?utils\\.ts"
116-
],
117-
"coveragePathIgnorePatterns": [
118-
"/dist/",
119-
"/node_modules/",
120-
"/src/typings/",
121-
"/src/utils/testing.ts",
122-
"/src/alt-langs/scheme/scm-slang",
123-
"/src/py-slang/"
124-
],
125-
"reporters": [
126-
"default",
127-
[
128-
"./node_modules/jest-html-reporter",
129-
{
130-
"pageTitle": "Test Report",
131-
"includeFailureMsg": true,
132-
"includeConsoleLog": true
133-
}
134-
]
135-
],
136-
"prettierPath": null
137-
}
88+
"packageManager": "yarn@4.6.0"
13889
}

0 commit comments

Comments
 (0)