Skip to content

Commit

Permalink
refactor: use mocha instead of jest to avoid crashes and other issues (
Browse files Browse the repository at this point in the history
…#208)

* refactor: use mocha instead of jest to avoid needing hacks

* chore: fix bundled tests with a reinstall

* chore: bump vscode version in CI

* chore: remove the experimental workaround from workflow

* chore: align workflow with microsoft recommendation

* chore: attempt to fix windows issue

* chore: fix typo in workflow

* chore: try again

* chore: again...

* chore: attempt to fix windows issue

* fix: use shared `expect` instance to avoid Windows issue

* chore: restore original content when testing schemas

* chore: temporarily disable windows tests
  • Loading branch information
byCedric committed Aug 31, 2023
1 parent a9b6c92 commit 92352ac
Show file tree
Hide file tree
Showing 34 changed files with 1,375 additions and 2,510 deletions.
9 changes: 9 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,13 @@
module.exports = {
ignorePatterns: ['node_modules/**', 'out/**', 'test/fixture/**'],
extends: 'universe/node',
overrides: [
{
files: ['*.test.ts', '*.e2e.ts'],
rules: {
// Chai uses patterns such as `expect(true).to.be.true`
'no-unused-expressions': 'off',
},
},
],
};
37 changes: 13 additions & 24 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,33 +58,21 @@ jobs:

# When bundled, these dependencies aren't available in normal environments.
# This kind-of fakes such environments, while keeping the required dev packages.
- name: 🧹 Remove Sucrase
run: yarn remove sucrase
- name: 🧹 Remove bundled dependencies
run: rm -rf node_modules/sucrase

- name: 🧪 Test project
uses: coactions/setup-xvfb@v1
with:
run: yarn test:vscode
run: xvfb-run -a yarn test:vscode
env:
# There is a testing issue in the latest vscode, instead of stable, we pin to the latest working version
# See: https://github.com/microsoft/vscode/issues/152938
VSCODE_VERSION: 1.77.3
VSCODE_VERSION: stable

vscode:
runs-on: ${{ matrix.os }}-latest
strategy:
fail-fast: false
matrix:
os: [ubuntu, macos, windows]
# There is a testing issue in the latest vscode, instead of stable, we pin to the latest working version
# See: https://github.com/microsoft/vscode/issues/152938
vscode: [oldest, 1.77.3]
# Instead of failing the whole workflow, we keep testing on stable to see when it's fixed
experimental: [false]
include:
- os: ubuntu
vscode: stable
experimental: true
os: [ubuntu, macos] # Windows is temporarily disabled due to issues on CI with previewing
vscode: [oldest, stable]
steps:
- name: 🏗 Setup repo
uses: actions/checkout@v3
Expand All @@ -93,7 +81,6 @@ jobs:
uses: ./.github/actions/setup-project
with:
with-fixture: true
without-cache: ${{ matrix.os == 'windows' }}

- name: 👷 Build project
run: yarn build
Expand All @@ -110,8 +97,10 @@ jobs:
: vscode
core.exportVariable('VSCODE_VERSION', target)
- name: 🧪 Test project
uses: coactions/setup-xvfb@v1
continue-on-error: ${{ matrix.experimental }}
with:
run: yarn test:vscode
- name: 🧪 Test project (Linux)
if: ${{ runner.os == 'Linux' }}
run: xvfb-run -a yarn test:vscode

- name: 🧪 Test project (MacOS/Windows)
if: ${{ runner.os != 'Linux' }}
run: yarn test:vscode
12 changes: 6 additions & 6 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
"args": [
"${workspaceFolder}/test/fixture",
"--extensionDevelopmentPath=${workspaceFolder}",
"--extensionTestsPath=${workspaceFolder}/out/test/jest/runner",
"--extensionTestsPath=${workspaceFolder}/out/test/mocha/vscode-runner",
"--disable-extensions"
],
"env": {
Expand All @@ -69,7 +69,7 @@
"args": [
"${workspaceFolder}/test/fixture",
"--extensionDevelopmentPath=${workspaceFolder}",
"--extensionTestsPath=${workspaceFolder}/out/test/jest/runner",
"--extensionTestsPath=${workspaceFolder}/out/test/mocha/vscode-runner",
"--disable-extensions"
],
"env": {
Expand All @@ -90,7 +90,7 @@
"args": [
"${workspaceFolder}/test/fixture",
"--extensionDevelopmentPath=${workspaceFolder}",
"--extensionTestsPath=${workspaceFolder}/out/test/jest/runner",
"--extensionTestsPath=${workspaceFolder}/out/test/mocha/vscode-runner",
"--disable-extensions"
],
"env": {
Expand All @@ -110,7 +110,7 @@
"args": [
"${workspaceFolder}/test/fixture",
"--extensionDevelopmentPath=${workspaceFolder}",
"--extensionTestsPath=${workspaceFolder}/out/test/jest/runner",
"--extensionTestsPath=${workspaceFolder}/out/test/mocha/vscode-runner",
"--disable-extensions"
],
"env": {
Expand All @@ -129,13 +129,13 @@
"args": [
"${workspaceFolder}/test/fixture",
"--extensionDevelopmentPath=${workspaceFolder}",
"--extensionTestsPath=${workspaceFolder}/out/test/jest/runner",
"--extensionTestsPath=${workspaceFolder}/out/test/mocha/vscode-runner",
"--disable-extensions"
],
"env": {
"VSCODE_EXPO_DEBUG": "vscode-expo*",
"VSCODE_EXPO_TELEMETRY_KEY": null,
"JEST_UPDATE_SNAPSHOTS": "true"
"mocha_UPDATE_SNAPSHOTS": "true"
},
"outFiles": [
"${workspaceFolder}/out/**/*.js"
Expand Down
9 changes: 0 additions & 9 deletions jest.scripts.js

This file was deleted.

10 changes: 0 additions & 10 deletions jest.vscode.js

This file was deleted.

16 changes: 10 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@
"build": "tsc -p ./",
"build:production": "webpack --mode production",
"clean": "git clean -xdf ./out ./.vscode-test *tsbuildinfo",
"test:vscode": "node ./out/test/jest/cli.js",
"test:scripts": "jest --config jest.scripts.js",
"test:vscode": "node ./out/test/mocha/vscode.js",
"test:scripts": "node ./scripts/mocha.js",
"lint": "eslint .",
"install:fixture": "yarn install --cwd ./test/fixture"
},
Expand All @@ -46,9 +46,11 @@
"@semantic-release/git": "^10.0.1",
"@sucrase/webpack-loader": "^2.0.0",
"@tsconfig/node16": "^1.0.3",
"@types/chai": "^4.3.5",
"@types/chai-subset": "^1.3.3",
"@types/debug": "^4.1.7",
"@types/jest": "^26.0.23",
"@types/minimatch": "^3.0.5",
"@types/mocha": "^10.0.1",
"@types/node": "^16.11.56",
"@types/node-fetch": "^2.6.2",
"@types/vscode": "^1.67.0",
Expand All @@ -58,19 +60,21 @@
"@vscode/test-electron": "^2.3.2",
"@vscode/vsce": "^2.16.0",
"arg": "^5.0.2",
"chai": "^4.3.8",
"chai-subset": "^1.6.0",
"conventional-changelog-conventionalcommits": "^5.0.0",
"debug": "^4.3.4",
"eslint": "^8.31.0",
"eslint-config-universe": "^11.1.1",
"execa": "^5.1.1",
"find-up": "^5.0.0",
"jest": "^26.6.3",
"jest-circus": "^26.6.3",
"jest-environment-node": "^26.6.2",
"glob": "^10.3.3",
"json-schema-traverse": "^1.0.0",
"json5": "^2.2.2",
"jsonc-parser": "^3.0.0",
"minimatch": "^3.0.4",
"mocha": "^10.2.0",
"mocha-chai-jest-snapshot": "^1.1.4",
"node-fetch": "^2.6.7",
"ovsx": "^0.8.0",
"parent-module": "^2.0.0",
Expand Down
32 changes: 32 additions & 0 deletions patches/jest-snapshot+28.1.3.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
diff --git a/node_modules/jest-snapshot/build/SnapshotResolver.js b/node_modules/jest-snapshot/build/SnapshotResolver.js
index a3d3b05..69f0132 100644
--- a/node_modules/jest-snapshot/build/SnapshotResolver.js
+++ b/node_modules/jest-snapshot/build/SnapshotResolver.js
@@ -13,7 +13,7 @@ var path = _interopRequireWildcard(require('path'));

var _chalk = _interopRequireDefault(require('chalk'));

-var _transform = require('@jest/transform');
+// var _transform = require('@jest/transform');

var _jestUtil = require('jest-util');

@@ -81,7 +81,9 @@ const cache = new Map();

const buildSnapshotResolver = async (
config,
- localRequire = (0, _transform.createTranspilingRequire)(config)
+ // Default to just `require` instead of the failing transpile require
+ localRequire = require,
+ // localRequire = (0, _transform.createTranspilingRequire)(config)
) => {
var _cache$get;

@@ -133,6 +135,7 @@ async function createCustomSnapshotResolver(
const custom = (0, _jestUtil.interopRequireDefault)(
await localRequire(snapshotResolverPath)
).default;
+
const keys = [
['resolveSnapshotPath', 'function'],
['resolveTestPath', 'function'],
26 changes: 26 additions & 0 deletions patches/mocha-chai-jest-snapshot+1.1.4.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
diff --git a/node_modules/mocha-chai-jest-snapshot/dist/helper.js b/node_modules/mocha-chai-jest-snapshot/dist/helper.js
index ea59a3c..8ac2b7f 100644
--- a/node_modules/mocha-chai-jest-snapshot/dist/helper.js
+++ b/node_modules/mocha-chai-jest-snapshot/dist/helper.js
@@ -5,14 +5,14 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
Object.defineProperty(exports, "__esModule", { value: true });
exports.readJestConfig = exports.snapshotOptions = void 0;
const path_1 = __importDefault(require("path"));
-const yargs_1 = __importDefault(require("yargs"));
+// const yargs_1 = __importDefault(require("yargs"));
const ARGV_CI = !!process.env.CI;
-const ARGV_UPDATE_SNAPSHOT = !!process.env.UPDATE_SNAPSHOT ||
- yargs_1.default
- .options({
- update: { type: "boolean", default: false },
- })
- .parseSync().update;
+const ARGV_UPDATE_SNAPSHOT = !!process.env.UPDATE_SNAPSHOT// ||
+ // yargs_1.default
+ // .options({
+ // update: { type: "boolean", default: false },
+ // })
+ // .parseSync().update;
exports.snapshotOptions = {
updateSnapshot: ARGV_CI && !ARGV_UPDATE_SNAPSHOT
? "none"
Loading

0 comments on commit 92352ac

Please sign in to comment.