mirror of
https://github.com/linux-odyssey/linux-odyssey.git
synced 2026-11-08 11:30:12 +08:00
refactor: replace Jest with bun
This commit is contained in:
1 parent
634dc8f987
commit
54225528b3
21 files changed
+66
-856
No files matched your search
@@ -2,7 +2,6 @@ module.exports = {
|
|||||||
root: true,
|
root: true,
|
||||||
env: {
|
env: {
|
||||||
node: true,
|
node: true,
|
||||||
jest: true,
|
|
||||||
},
|
},
|
||||||
globals: {
|
globals: {
|
||||||
Bun: 'readonly',
|
Bun: 'readonly',
|
||||||
|
|||||||
@@ -15,11 +15,6 @@ jobs:
|
|||||||
with:
|
with:
|
||||||
bun-version: 1.3.14
|
bun-version: 1.3.14
|
||||||
|
|
||||||
# Jest still runs on Node until tests move to `bun test`
|
|
||||||
- uses: actions/setup-node@v3
|
|
||||||
with:
|
|
||||||
node-version: 20
|
|
||||||
|
|
||||||
- name: Install dependencies
|
- name: Install dependencies
|
||||||
run: bun install --frozen-lockfile
|
run: bun install --frozen-lockfile
|
||||||
|
|
||||||
|
|||||||
Vendored
+2
-2
@@ -4,9 +4,9 @@
|
|||||||
{
|
{
|
||||||
"type": "node",
|
"type": "node",
|
||||||
"request": "launch",
|
"request": "launch",
|
||||||
"name": "File Graph Jest",
|
"name": "File Graph Tests",
|
||||||
"runtimeExecutable": "bun",
|
"runtimeExecutable": "bun",
|
||||||
"args": ["run", "test", "packages/file-graph", "--runInBand"],
|
"args": ["test", "packages/file-graph"],
|
||||||
"cwd": "${workspaceFolder}",
|
"cwd": "${workspaceFolder}",
|
||||||
"console": "integratedTerminal",
|
"console": "integratedTerminal",
|
||||||
"internalConsoleOptions": "neverOpen"
|
"internalConsoleOptions": "neverOpen"
|
||||||
|
|||||||
@@ -1,6 +0,0 @@
|
|||||||
module.exports = {
|
|
||||||
presets: [
|
|
||||||
['@babel/preset-env', { targets: { node: 'current' } }],
|
|
||||||
'@babel/preset-typescript',
|
|
||||||
],
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
[test]
|
||||||
|
coverage = true
|
||||||
|
coverageDir = "coverage"
|
||||||
-201
@@ -1,201 +0,0 @@
|
|||||||
/**
|
|
||||||
* For a detailed explanation regarding each configuration property, visit:
|
|
||||||
* https://jestjs.io/docs/configuration
|
|
||||||
*/
|
|
||||||
|
|
||||||
import type { Config } from 'jest'
|
|
||||||
|
|
||||||
const config: Config = {
|
|
||||||
// All imported modules in your tests should be mocked automatically
|
|
||||||
// automock: false,
|
|
||||||
|
|
||||||
// Stop running tests after `n` failures
|
|
||||||
// bail: 0,
|
|
||||||
|
|
||||||
// The directory where Jest should store its cached dependency information
|
|
||||||
// cacheDirectory: "/tmp/jest_rs",
|
|
||||||
|
|
||||||
// Automatically clear mock calls, instances, contexts and results before every test
|
|
||||||
// clearMocks: false,
|
|
||||||
|
|
||||||
// Indicates whether the coverage information should be collected while executing the test
|
|
||||||
collectCoverage: true,
|
|
||||||
|
|
||||||
// An array of glob patterns indicating a set of files for which coverage information should be collected
|
|
||||||
// collectCoverageFrom: undefined,
|
|
||||||
|
|
||||||
// The directory where Jest should output its coverage files
|
|
||||||
coverageDirectory: 'coverage',
|
|
||||||
|
|
||||||
// An array of regexp pattern strings used to skip coverage collection
|
|
||||||
// coveragePathIgnorePatterns: [
|
|
||||||
// "/node_modules/"
|
|
||||||
// ],
|
|
||||||
|
|
||||||
// Indicates which provider should be used to instrument code for coverage
|
|
||||||
coverageProvider: 'v8',
|
|
||||||
|
|
||||||
// A list of reporter names that Jest uses when writing coverage reports
|
|
||||||
// coverageReporters: [
|
|
||||||
// "json",
|
|
||||||
// "text",
|
|
||||||
// "lcov",
|
|
||||||
// "clover"
|
|
||||||
// ],
|
|
||||||
|
|
||||||
// An object that configures minimum threshold enforcement for coverage results
|
|
||||||
// coverageThreshold: undefined,
|
|
||||||
|
|
||||||
// A path to a custom dependency extractor
|
|
||||||
// dependencyExtractor: undefined,
|
|
||||||
|
|
||||||
// Make calling deprecated APIs throw helpful error messages
|
|
||||||
// errorOnDeprecated: false,
|
|
||||||
|
|
||||||
// The default configuration for fake timers
|
|
||||||
// fakeTimers: {
|
|
||||||
// "enableGlobally": false
|
|
||||||
// },
|
|
||||||
|
|
||||||
// Force coverage collection from ignored files using an array of glob patterns
|
|
||||||
// forceCoverageMatch: [],
|
|
||||||
|
|
||||||
// A path to a module which exports an async function that is triggered once before all test suites
|
|
||||||
// globalSetup: undefined,
|
|
||||||
|
|
||||||
// A path to a module which exports an async function that is triggered once after all test suites
|
|
||||||
// globalTeardown: undefined,
|
|
||||||
|
|
||||||
// A set of global variables that need to be available in all test environments
|
|
||||||
// globals: {},
|
|
||||||
|
|
||||||
// The maximum amount of workers used to run your tests. Can be specified as % or a number. E.g. maxWorkers: 10% will use 10% of your CPU amount + 1 as the maximum worker number. maxWorkers: 2 will use a maximum of 2 workers.
|
|
||||||
// maxWorkers: "50%",
|
|
||||||
|
|
||||||
// An array of directory names to be searched recursively up from the requiring module's location
|
|
||||||
// moduleDirectories: [
|
|
||||||
// "node_modules"
|
|
||||||
// ],
|
|
||||||
|
|
||||||
// An array of file extensions your modules use
|
|
||||||
// moduleFileExtensions: [
|
|
||||||
// "js",
|
|
||||||
// "mjs",
|
|
||||||
// "cjs",
|
|
||||||
// "jsx",
|
|
||||||
// "ts",
|
|
||||||
// "tsx",
|
|
||||||
// "json",
|
|
||||||
// "node"
|
|
||||||
// ],
|
|
||||||
|
|
||||||
// A map from regular expressions to module names or to arrays of module names that allow to stub out resources with a single module
|
|
||||||
moduleNameMapper: {
|
|
||||||
'^(\\.{1,2}/.*)\\.js$': '$1', // Redirect .js imports to .ts files
|
|
||||||
},
|
|
||||||
|
|
||||||
// An array of regexp pattern strings, matched against all module paths before considered 'visible' to the module loader
|
|
||||||
// modulePathIgnorePatterns: [],
|
|
||||||
|
|
||||||
// Activates notifications for test results
|
|
||||||
// notify: false,
|
|
||||||
|
|
||||||
// An enum that specifies notification mode. Requires { notify: true }
|
|
||||||
// notifyMode: "failure-change",
|
|
||||||
|
|
||||||
// A preset that is used as a base for Jest's configuration
|
|
||||||
// preset: undefined,
|
|
||||||
|
|
||||||
// Run tests from one or more projects
|
|
||||||
// projects: undefined,
|
|
||||||
|
|
||||||
// Use this configuration option to add custom reporters to Jest
|
|
||||||
// reporters: undefined,
|
|
||||||
|
|
||||||
// Automatically reset mock state before every test
|
|
||||||
// resetMocks: false,
|
|
||||||
|
|
||||||
// Reset the module registry before running each individual test
|
|
||||||
// resetModules: false,
|
|
||||||
|
|
||||||
// A path to a custom resolver
|
|
||||||
// resolver: undefined,
|
|
||||||
|
|
||||||
// Automatically restore mock state and implementation before every test
|
|
||||||
// restoreMocks: false,
|
|
||||||
|
|
||||||
// The root directory that Jest should scan for tests and modules within
|
|
||||||
// rootDir: undefined,
|
|
||||||
|
|
||||||
// A list of paths to directories that Jest should use to search for files in
|
|
||||||
// roots: [
|
|
||||||
// "<rootDir>"
|
|
||||||
// ],
|
|
||||||
|
|
||||||
// Allows you to use a custom runner instead of Jest's default test runner
|
|
||||||
// runner: "jest-runner",
|
|
||||||
|
|
||||||
// The paths to modules that run some code to configure or set up the testing environment before each test
|
|
||||||
// setupFiles: [],
|
|
||||||
|
|
||||||
// A list of paths to modules that run some code to configure or set up the testing framework before each test
|
|
||||||
// setupFilesAfterEnv: [],
|
|
||||||
|
|
||||||
// The number of seconds after which a test is considered as slow and reported as such in the results.
|
|
||||||
// slowTestThreshold: 5,
|
|
||||||
|
|
||||||
// A list of paths to snapshot serializer modules Jest should use for snapshot testing
|
|
||||||
// snapshotSerializers: [],
|
|
||||||
|
|
||||||
// The test environment that will be used for testing
|
|
||||||
// testEnvironment: "jest-environment-node",
|
|
||||||
|
|
||||||
// Options that will be passed to the testEnvironment
|
|
||||||
// testEnvironmentOptions: {},
|
|
||||||
|
|
||||||
// Adds a location field to test results
|
|
||||||
// testLocationInResults: false,
|
|
||||||
|
|
||||||
// The glob patterns Jest uses to detect test files
|
|
||||||
// testMatch: [
|
|
||||||
// "**/__tests__/**/*.[jt]s?(x)",
|
|
||||||
// "**/?(*.)+(spec|test).[tj]s?(x)"
|
|
||||||
// ],
|
|
||||||
|
|
||||||
// An array of regexp pattern strings that are matched against all test paths, matched tests are skipped
|
|
||||||
// testPathIgnorePatterns: [
|
|
||||||
// "/node_modules/"
|
|
||||||
// ],
|
|
||||||
|
|
||||||
// The regexp pattern or array of patterns that Jest uses to detect test files
|
|
||||||
// testRegex: [],
|
|
||||||
|
|
||||||
// This option allows the use of a custom results processor
|
|
||||||
// testResultsProcessor: undefined,
|
|
||||||
|
|
||||||
// This option allows use of a custom test runner
|
|
||||||
// testRunner: "jest-circus/runner",
|
|
||||||
|
|
||||||
// A map from regular expressions to paths to transformers
|
|
||||||
// transform: undefined,
|
|
||||||
|
|
||||||
// An array of regexp pattern strings that are matched against all source file paths, matched files will skip transformation
|
|
||||||
// transformIgnorePatterns: [
|
|
||||||
// "/node_modules/",
|
|
||||||
// "\\.pnp\\.[^\\/]+$"
|
|
||||||
// ],
|
|
||||||
|
|
||||||
// An array of regexp pattern strings that are matched against all modules before the module loader will automatically return a mock for them
|
|
||||||
// unmockedModulePathPatterns: undefined,
|
|
||||||
|
|
||||||
// Indicates whether each individual test should be reported during the run
|
|
||||||
// verbose: undefined,
|
|
||||||
|
|
||||||
// An array of regexp patterns that are matched against all source file paths before re-running tests in watch mode
|
|
||||||
// watchPathIgnorePatterns: [],
|
|
||||||
|
|
||||||
// Whether to use watchman for file crawling
|
|
||||||
// watchman: true,
|
|
||||||
}
|
|
||||||
|
|
||||||
export default config
|
|
||||||
+1
-9
@@ -19,7 +19,7 @@
|
|||||||
"server": "bun run --filter server dev",
|
"server": "bun run --filter server dev",
|
||||||
"lint": "eslint .",
|
"lint": "eslint .",
|
||||||
"format": "prettier --ignore-path .prettierignore --write app server",
|
"format": "prettier --ignore-path .prettierignore --write app server",
|
||||||
"test": "node --experimental-vm-modules --no-warnings node_modules/jest/bin/jest.js",
|
"test": "bun test",
|
||||||
"test:e2e": "bun run --filter tests test",
|
"test:e2e": "bun run --filter tests test",
|
||||||
"test:open": "bun run --filter tests test:open",
|
"test:open": "bun run --filter tests test:open",
|
||||||
"analytics": "bun run --filter analytics dev",
|
"analytics": "bun run --filter analytics dev",
|
||||||
@@ -29,17 +29,11 @@
|
|||||||
"type-check": "bun run --filter server --filter analytics --filter app type-check"
|
"type-check": "bun run --filter server --filter analytics --filter app type-check"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@babel/core": "^7.29.6",
|
|
||||||
"@babel/preset-env": "^7.24.0",
|
|
||||||
"@babel/preset-typescript": "^7.23.3",
|
|
||||||
"@jest/globals": "^29.7.0",
|
|
||||||
"@types/bun": "^1.4.2",
|
"@types/bun": "^1.4.2",
|
||||||
"@types/jest": "^29.5.12",
|
|
||||||
"@types/node": "^20.10.4",
|
"@types/node": "^20.10.4",
|
||||||
"@typescript-eslint/eslint-plugin": "^6.21.0",
|
"@typescript-eslint/eslint-plugin": "^6.21.0",
|
||||||
"@typescript-eslint/parser": "^6.21.0",
|
"@typescript-eslint/parser": "^6.21.0",
|
||||||
"@vue/eslint-config-prettier": "^7.1.0",
|
"@vue/eslint-config-prettier": "^7.1.0",
|
||||||
"babel-jest": "^29.7.0",
|
|
||||||
"concurrently": "^8.2.2",
|
"concurrently": "^8.2.2",
|
||||||
"eslint": "^8.56.0",
|
"eslint": "^8.56.0",
|
||||||
"eslint-config-airbnb-base": "^15.0.0",
|
"eslint-config-airbnb-base": "^15.0.0",
|
||||||
@@ -50,9 +44,7 @@
|
|||||||
"eslint-plugin-prettier": "^5.1.3",
|
"eslint-plugin-prettier": "^5.1.3",
|
||||||
"eslint-plugin-vue": "^9.15.1",
|
"eslint-plugin-vue": "^9.15.1",
|
||||||
"globals": "^16.0.0",
|
"globals": "^16.0.0",
|
||||||
"jest": "^29.7.0",
|
|
||||||
"prettier": "^3.0.0",
|
"prettier": "^3.0.0",
|
||||||
"ts-node": "^10.9.2",
|
|
||||||
"typescript": "^5.3.3",
|
"typescript": "^5.3.3",
|
||||||
"vue-eslint-parser": "^9.4.2"
|
"vue-eslint-parser": "^9.4.2"
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { describe, test, expect } from '@jest/globals'
|
import { describe, test, expect, beforeEach } from 'bun:test'
|
||||||
import File from '../file.js'
|
import File from '../file.js'
|
||||||
|
|
||||||
describe('File', () => {
|
describe('File', () => {
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { describe, test, expect } from '@jest/globals'
|
import { describe, test, expect, beforeEach } from 'bun:test'
|
||||||
import FileGraph from '../fileGraph.js'
|
import FileGraph from '../fileGraph.js'
|
||||||
import FileNode from '../fileNode.js'
|
import FileNode from '../fileNode.js'
|
||||||
import { FileObject } from '../file.js'
|
import { FileObject } from '../file.js'
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { describe, test, expect } from '@jest/globals'
|
import { describe, test, expect, beforeEach } from 'bun:test'
|
||||||
import { ParentNotExistsError } from '../errors.js'
|
import { ParentNotExistsError } from '../errors.js'
|
||||||
import FileNode, { IFileNode } from '../fileNode.js'
|
import FileNode, { IFileNode } from '../fileNode.js'
|
||||||
import { FileObject } from '../file.js'
|
import { FileObject } from '../file.js'
|
||||||
|
|||||||
@@ -1,28 +1,7 @@
|
|||||||
import { test, expect } from '@jest/globals'
|
import { test, expect } from 'bun:test'
|
||||||
import { IFileExistenceChecker, IFileInput } from '../schema'
|
|
||||||
import { checkFiles } from '../condition/FileMatcher.js'
|
import { checkFiles } from '../condition/FileMatcher.js'
|
||||||
import { Condition } from '../condition/Condition.js'
|
import { Condition } from '../condition/Condition.js'
|
||||||
|
import { MockFileChecker } from './mockFileChecker'
|
||||||
export class MockFileChecker implements IFileExistenceChecker {
|
|
||||||
private files: IFileInput[] = [
|
|
||||||
{
|
|
||||||
path: '/home/user/hello.txt',
|
|
||||||
type: 'file',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
path: '/home/user/world.txt',
|
|
||||||
type: 'file',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
path: '/home/user/Downloads',
|
|
||||||
type: 'directory',
|
|
||||||
},
|
|
||||||
]
|
|
||||||
|
|
||||||
async exists(file: IFileInput): Promise<boolean> {
|
|
||||||
return this.files.some((f) => f.path === file.path && f.type === file.type)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
test('file matcher', async () => {
|
test('file matcher', async () => {
|
||||||
const checker = new MockFileChecker()
|
const checker = new MockFileChecker()
|
||||||
|
|||||||
@@ -1,11 +1,11 @@
|
|||||||
import { test, expect } from '@jest/globals'
|
import { it, test, expect } from 'bun:test'
|
||||||
import { Condition } from '../condition/Condition'
|
import { Condition } from '../condition/Condition'
|
||||||
import { OutputMatcher } from '../condition/OutputMatcher'
|
import { OutputMatcher } from '../condition/OutputMatcher'
|
||||||
import { PwdMatcher } from '../condition/PwdMatcher'
|
import { PwdMatcher } from '../condition/PwdMatcher'
|
||||||
import { CommandMatcher } from '../condition/CommandMatcher'
|
import { CommandMatcher } from '../condition/CommandMatcher'
|
||||||
import { ErrorMatcher } from '../condition/ErrorMatcher'
|
import { ErrorMatcher } from '../condition/ErrorMatcher'
|
||||||
import { conditionSchema } from '../schema'
|
import { conditionSchema } from '../schema'
|
||||||
import { MockFileChecker } from './asyncCondition.test'
|
import { MockFileChecker } from './mockFileChecker'
|
||||||
|
|
||||||
test('command match', () => {
|
test('command match', () => {
|
||||||
const matcher = new CommandMatcher('^echo start$')
|
const matcher = new CommandMatcher('^echo start$')
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import { expect, it, describe } from '@jest/globals'
|
import { describe, it, expect } from 'bun:test'
|
||||||
import { IQuest } from '../schema'
|
import { IQuest } from '../schema'
|
||||||
import { GameSession } from '../Session'
|
import { GameSession } from '../Session'
|
||||||
import { MockFileChecker } from './asyncCondition.test'
|
import { MockFileChecker } from './mockFileChecker'
|
||||||
|
|
||||||
const quest: IQuest = {
|
const quest: IQuest = {
|
||||||
id: 'quest1',
|
id: 'quest1',
|
||||||
|
|||||||
@@ -0,0 +1,22 @@
|
|||||||
|
import type { IFileExistenceChecker, IFileInput } from '../schema'
|
||||||
|
|
||||||
|
export class MockFileChecker implements IFileExistenceChecker {
|
||||||
|
private files: IFileInput[] = [
|
||||||
|
{
|
||||||
|
path: '/home/user/hello.txt',
|
||||||
|
type: 'file',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
path: '/home/user/world.txt',
|
||||||
|
type: 'file',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
path: '/home/user/Downloads',
|
||||||
|
type: 'directory',
|
||||||
|
},
|
||||||
|
]
|
||||||
|
|
||||||
|
async exists(file: IFileInput): Promise<boolean> {
|
||||||
|
return this.files.some((f) => f.path === file.path && f.type === file.type)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
import { expect, describe, it } from '@jest/globals'
|
import { describe, it, expect } from 'bun:test'
|
||||||
import { IQuest } from '../schema'
|
import { IQuest } from '../schema'
|
||||||
import { GameSession } from '../Session'
|
import { GameSession } from '../Session'
|
||||||
import { MockFileChecker } from './asyncCondition.test'
|
import { MockFileChecker } from './mockFileChecker'
|
||||||
|
|
||||||
const quest: IQuest = {
|
const quest: IQuest = {
|
||||||
id: 'quest1',
|
id: 'quest1',
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import { test, expect } from '@jest/globals'
|
import { test, expect } from 'bun:test'
|
||||||
import { Stage } from '../Stage'
|
import { Stage } from '../Stage'
|
||||||
import { MockFileChecker } from './asyncCondition.test'
|
import { MockFileChecker } from './mockFileChecker'
|
||||||
|
|
||||||
const checker = new MockFileChecker()
|
const checker = new MockFileChecker()
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { test, expect } from '@jest/globals'
|
import { test, expect } from 'bun:test'
|
||||||
import { isValidEmail, isValidUsername } from '../auth'
|
import { isValidEmail, isValidUsername } from '../auth'
|
||||||
|
|
||||||
test('check valid username', () => {
|
test('check valid username', () => {
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { describe, it, expect } from '@jest/globals'
|
import { describe, it, expect } from 'bun:test'
|
||||||
import { buildFileCheckCmd, File } from '../commands'
|
import { buildFileCheckCmd, File } from '../commands'
|
||||||
|
|
||||||
describe('buildFileCheckCmd function', () => {
|
describe('buildFileCheckCmd function', () => {
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { describe, it, expect } from '@jest/globals'
|
import { describe, it, expect } from 'bun:test'
|
||||||
import DAG from '../dag'
|
import DAG from '../dag'
|
||||||
|
|
||||||
describe('dag layers', () => {
|
describe('dag layers', () => {
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
import { describe, it, expect } from 'bun:test'
|
||||||
import mongoose from 'mongoose'
|
import mongoose from 'mongoose'
|
||||||
import Pagination, { ASC, DESC } from '../src/models/pagination.js'
|
import Pagination, { ASC, DESC } from '../src/models/pagination.js'
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user