Skip to content

Commit

Permalink
test: migrate to node test runner from vitest
Browse files Browse the repository at this point in the history
  • Loading branch information
arianrhodsandlot committed Jan 22, 2025
1 parent b4461cb commit 2fc2763
Show file tree
Hide file tree
Showing 14 changed files with 156 additions and 729 deletions.
13 changes: 5 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,11 @@
"docs:build": "astro build --root docs",
"docs:dev": "astro dev --root docs",
"eslint": "eslint --no-warn-ignored",
"lint": "node --run=eslint -- src",
"lint": "node --run=eslint -- src tests",
"prepare": "simple-git-hooks",
"test": "vitest run -c tests/integration/vitest.config && pnpm build && pnpm test:e2e",
"test": "node --run=test:integration && node --run=test:e2e",
"test:e2e": "playwright test -c tests/e2e",
"test:integration": "vitest -c tests/integration/vitest.config"
"test:integration": "node --test tests/integration/**/*.spec.ts"
},
"simple-git-hooks": {
"pre-commit": "pnpm lint-staged"
Expand All @@ -64,6 +64,7 @@
"@arianrhodsandlot/eslint-config": "0.17.1",
"@arianrhodsandlot/release-kit": "0.1.6",
"@astrojs/starlight": "0.31.1",
"@happy-dom/global-registrator": "16.7.2",
"@playwright/test": "1.49.1",
"@types/is-ci": "3.0.4",
"@types/node": "22.10.7",
Expand All @@ -72,16 +73,12 @@
"eslint": "9.18.0",
"ini": "5.0.0",
"is-ci": "4.1.0",
"jiti": "2.4.2",
"jsdom": "26.0.0",
"lint-staged": "15.4.1",
"path-browserify": "1.0.1",
"serve": "14.2.4",
"sharp": "0.33.5",
"simple-git-hooks": "2.11.1",
"typescript": "5.7.3",
"vite": "6.0.10",
"vitest": "3.0.2"
"vite": "6.0.10"
},
"packageManager": "pnpm@9.15.4"
}
604 changes: 17 additions & 587 deletions pnpm-lock.yaml

Large diffs are not rendered by default.

14 changes: 9 additions & 5 deletions src/classes/emulator-file-system.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { blobToBuffer, checkIsAborted, delay, textEncoder } from '../libs/utils'
import { vendors } from '../libs/vendors'
import { blobToBuffer, checkIsAborted, delay, textEncoder } from '../libs/utils.ts'
import { vendors } from '../libs/vendors.ts'
import type { RetroArchEmscriptenModule } from '../types/retroarch-emscripten'

const { ini, path } = vendors
Expand Down Expand Up @@ -83,7 +83,7 @@ export class EmulatorFileSystem {

async waitForFile(fileName: string) {
const maxRetries = 30
let buffer
let buffer: Uint8Array | undefined
let isFinished = false
let retryTimes = 0
while (retryTimes <= maxRetries && !isFinished) {
Expand All @@ -92,7 +92,9 @@ export class EmulatorFileSystem {
checkIsAborted(this.signal)
try {
const newBuffer = this.readFile(fileName, 'binary').buffer
isFinished = buffer?.byteLength > 0 && buffer?.byteLength === newBuffer.byteLength
if (buffer) {
isFinished = buffer.byteLength > 0 && buffer.byteLength === newBuffer.byteLength
}
buffer = newBuffer
} catch (error) {
console.warn(error)
Expand Down Expand Up @@ -125,7 +127,9 @@ export class EmulatorFileSystem {

const clonedConfig: typeof config = {}
for (const key in config) {
clonedConfig[key] = `__${config[key]}__`
if (Object.hasOwn(config, key)) {
clonedConfig[key] = `__${config[key]}__`
}
}
const fileContent = ini.stringify(clonedConfig, { platform: 'linux', whitespace: true }).replaceAll('__', '"')
await this.writeFile(path, fileContent)
Expand Down
8 changes: 4 additions & 4 deletions src/classes/emulator-options.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { getGlobalOptions } from '../libs/options.js'
import { merge, urlBaseName } from '../libs/utils.js'
import { getGlobalOptions } from '../libs/options.ts'
import { merge, urlBaseName } from '../libs/utils.ts'
import type {
NostalgistOptions,
NostalgistOptionsFile,
NostalgistResolveFileFunction,
} from '../types/nostalgist-options.js'
import type { RetroArchEmscriptenModuleOptions } from '../types/retroarch-emscripten'
} from '../types/nostalgist-options.ts'
import type { RetroArchEmscriptenModuleOptions } from '../types/retroarch-emscripten.ts'

export class EmulatorOptions {
beforeLaunch?: (() => Promise<void> | void) | undefined
Expand Down
14 changes: 7 additions & 7 deletions src/classes/emulator.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { coreInfoMap } from '../constants/core-info'
import { keyboardCodeMap } from '../constants/keyboard-code-map'
import { getEmscriptenModuleOverrides } from '../libs/emscripten'
import { coreInfoMap } from '../constants/core-info.ts'
import { keyboardCodeMap } from '../constants/keyboard-code-map.ts'
import { getEmscriptenModuleOverrides } from '../libs/emscripten.ts'
import {
blobToBuffer,
checkIsAborted,
Expand All @@ -9,11 +9,11 @@ import {
padZero,
textEncoder,
updateStyle,
} from '../libs/utils'
import { vendors } from '../libs/vendors'
import type { RetroArchCommand } from '../types/retroarch-command'
} from '../libs/utils.ts'
import { vendors } from '../libs/vendors.ts'
import type { RetroArchCommand } from '../types/retroarch-command.ts'
import type { RetroArchEmscriptenModule } from '../types/retroarch-emscripten'
import { EmulatorFileSystem } from './emulator-file-system'
import { EmulatorFileSystem } from './emulator-file-system.ts'
import type { EmulatorOptions } from './emulator-options'

const { ini, path } = vendors
Expand Down
12 changes: 6 additions & 6 deletions src/classes/nostalgist.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import { Emulator } from '../classes/emulator'
import { systemCoreMap } from '../constants/system'
import { getGlobalOptions, resetGlobalOptions, updateGlobalOptions } from '../libs/options'
import { checkIsAborted, merge } from '../libs/utils'
import { vendors } from '../libs/vendors'
import { systemCoreMap } from '../constants/system.ts'
import { getGlobalOptions, resetGlobalOptions, updateGlobalOptions } from '../libs/options.ts'
import { checkIsAborted, merge } from '../libs/utils.ts'
import { vendors } from '../libs/vendors.ts'
import type {
NostalgistLaunchOptions,
NostalgistLaunchRomOptions,
Expand All @@ -11,7 +10,8 @@ import type {
NostalgistOptionsPartial,
} from '../types/nostalgist-options'
import type { RetroArchCommand } from '../types/retroarch-command'
import { EmulatorOptions } from './emulator-options'
import { EmulatorOptions } from './emulator-options.ts'
import { Emulator } from './emulator.ts'

export class Nostalgist {
static readonly Nostalgist = Nostalgist
Expand Down
2 changes: 1 addition & 1 deletion src/index-umd.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export { Nostalgist as default } from './classes/nostalgist'
export { Nostalgist as default } from './classes/nostalgist.ts'
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export { Nostalgist } from './classes/nostalgist'
export { Nostalgist } from './classes/nostalgist.ts'
2 changes: 1 addition & 1 deletion src/libs/emscripten.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { RetroArchEmscriptenModuleOptions } from '../types/retroarch-emscripten'
import type { RetroArchEmscriptenModuleOptions } from '../types/retroarch-emscripten.ts'

export function getEmscriptenModuleOverrides(overrides: RetroArchEmscriptenModuleOptions) {
let resolveRunDependenciesPromise: () => void
Expand Down
6 changes: 3 additions & 3 deletions src/libs/options.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { NostalgistOptions, NostalgistOptionsPartial } from '../types/nostalgist-options'
import type { NostalgistOptions, NostalgistOptionsPartial } from '../types/nostalgist-options.ts'
import type { RetroArchConfig } from '../types/retroarch-config'
import { isAbsoluteUrl, merge } from './utils'
import { vendors } from './vendors'
import { isAbsoluteUrl, merge } from './utils.ts'
import { vendors } from './vendors.ts'

const { path } = vendors

Expand Down
2 changes: 1 addition & 1 deletion src/libs/utils.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { vendors } from './vendors'
import { vendors } from './vendors.ts'

const { path } = vendors

Expand Down
4 changes: 2 additions & 2 deletions tests/e2e/playwright.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@ export default defineConfig({
snapshotPathTemplate: '{testDir}/snapshots/{testFilePath}/{testName}/{arg}{ext}',
testMatch: 'tests/e2e/**/*.spec.ts',
updateSnapshots: 'missing',
use: { baseURL: 'http://localhost:3000/', headless: true },
webServer: { command: 'pnpm serve -n', port: 3000, reuseExistingServer: !isCi },
use: { baseURL: 'http://localhost:8000/', headless: true },
webServer: { command: 'python3 -m http.server', cwd: '../..', port: 8000, reuseExistingServer: !isCi },
})
Loading

0 comments on commit 2fc2763

Please sign in to comment.