diff --git a/.eslintrc.json b/.eslintrc.json index b90ba13..6aa88dc 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -13,7 +13,13 @@ "ignorePatterns": ["build/"], "parser": "@typescript-eslint/parser", "parserOptions": { - "project": ["./tsconfig.json", "./test/tsconfig.json"] + "project": [ + "./src/cli/tsconfig.json", + "./src/client/tsconfig.json", + "./src/common/tsconfig.json", + "./src/server/tsconfig.json", + "./test/tsconfig.json" + ] }, "plugins": [ "@typescript-eslint" diff --git a/.gitignore b/.gitignore index 87dd4a4..cdc09fa 100644 --- a/.gitignore +++ b/.gitignore @@ -13,3 +13,4 @@ node_modules/ coverage/ build/ dist/ +*.tsbuildinfo diff --git a/package.json b/package.json index fdcfde8..e8907d7 100644 --- a/package.json +++ b/package.json @@ -3,29 +3,29 @@ "description": "playwright, but unit test", "version": "0.1.0", "type": "module", - "main": "./build/index.js", - "types": "./build/index.d.ts", + "main": "./build/client/api.js", + "types": "./build/client/api.d.ts", "exports": { - ".": "./build/index.js", - "./cli": "./build/cli.js", - "./node": "./build/node.js", + ".": "./build/client/api.js", + "./cli": "./build/cli/api.js", + "./node": "./build/server/api.js", "./package.json": "./package.json" }, "typesVersions": { "<4.7": { ".": [ - "./build/index.d.ts" + "./build/client/api.d.ts" ], "cli": [ - "./build/cli.d.ts" + "./build/cli/api.d.ts" ], "node": [ - "./build/node.d.ts" + "./build/server/api.d.ts" ] } }, "bin": { - "wrightplay": "./build/cli.js" + "wrightplay": "./build/cli/index.js" }, "browser": { "mocha": "mocha/mocha.js", @@ -37,13 +37,14 @@ "repository": "github:PaperStrike/wrightplay", "license": "ISC", "scripts": { - "build": "tsc", + "build": "tsc -b", "lint": "eslint .", "prepare": "npm run build", - "test-entry": "ts-node-esm src/cli.ts ww=test/entry/worker.ts test/entry/*.test.*", - "test-handle": "ts-node-esm src/cli.ts test/handle/*.test.*", - "test-route": "ts-node-esm src/cli.ts test/route/*.test.*", - "test": "ts-node-esm src/cli.ts ww=test/entry/worker.ts test/**/*.test.ts !**/third-party", + "cli": "ts-node-esm src/cli/index.ts", + "test-entry": "npm run cli -- ww=test/entry/worker.ts test/entry/*.test.*", + "test-handle": "npm run cli -- test/handle/*.test.*", + "test-route": "npm run cli -- test/route/*.test.*", + "test": "npm run cli -- ww=test/entry/worker.ts test/**/*.test.ts !**/third-party", "test-chromium": "npm test -- --browser chromium", "test-firefox": "npm test -- --browser firefox", "test-webkit": "npm test -- --browser webkit", @@ -52,7 +53,8 @@ "files": [ "build", "static", - "src" + "src", + "!*.tsbuildinfo" ], "keywords": [ "test", diff --git a/src/cli.ts b/src/cli/api.ts similarity index 86% rename from src/cli.ts rename to src/cli/api.ts index 4996425..d6029a9 100644 --- a/src/cli.ts +++ b/src/cli/api.ts @@ -1,21 +1,19 @@ -#!/usr/bin/env node - import { createRequire } from 'node:module'; import { Command, Option } from '@commander-js/extra-typings'; -import Runner, { BrowserServerOptions, RunnerOptions } from './Runner.js'; -import { ConfigOptions } from './node.js'; +import Runner, { BrowserServerOptions, RunnerOptions } from '../server/Runner.js'; +import { ConfigOptions } from '../server/api.js'; import configSearcher from './configSearcher.js'; const require = createRequire(import.meta.url); -const pkgJSON = require('../package.json') as { +const pkgJSON = require('../../package.json') as { name: string; version: string; }; // Simple JSON.parse. Error by Playwright if any. -const parseBrowserServerOptions = (str: string) => JSON.parse(str) as BrowserServerOptions; +export const parseBrowserServerOptions = (str: string) => JSON.parse(str) as BrowserServerOptions; -export const program = new Command() +const command = new Command() .version(pkgJSON.version) .name(pkgJSON.name) .argument('[test-or-entry...]', 'Test files and entry points. Use glob for tests, name=path for entries') @@ -30,7 +28,7 @@ export const program = new Command() .addOption(new Option('-d, --debug', 'Run browser in headed mode. Defaults to `false`')) .addOption(new Option('--no-cov', 'Disable coverage file output. This only matters when `NODE_V8_COVERAGE` is set. Defaults to `false` on chromium, `true` on firefox and webkit')); -export type CLIOptions = ReturnType; +export type CLIOptions = ReturnType; export const parseRunnerOptionsFromCLI = async ( testAndEntries: string[], @@ -74,8 +72,8 @@ export const parseRunnerOptionsFromCLI = async ( }); }; -program - .action(async (testAndEntries: string[], options: CLIOptions) => { +export const program = command + .action(async (testAndEntries, options) => { const runnerOptionsList = await parseRunnerOptionsFromCLI(testAndEntries, options); await runnerOptionsList.reduce(async (last, runnerOptions) => { await last; @@ -83,5 +81,4 @@ program const exitCode = await runner.runTests(); process.exitCode ||= exitCode; }, Promise.resolve()); - }) - .parse(); + }); diff --git a/src/configSearcher.ts b/src/cli/configSearcher.ts similarity index 100% rename from src/configSearcher.ts rename to src/cli/configSearcher.ts diff --git a/src/cli/index.ts b/src/cli/index.ts new file mode 100644 index 0000000..f8d1a88 --- /dev/null +++ b/src/cli/index.ts @@ -0,0 +1,5 @@ +#!/usr/bin/env node + +import { program } from './api.js'; + +program.parse(); diff --git a/src/cli/tsconfig.json b/src/cli/tsconfig.json new file mode 100644 index 0000000..abe66e7 --- /dev/null +++ b/src/cli/tsconfig.json @@ -0,0 +1,12 @@ +{ + "extends": "../../tsconfig.base.json", + "compilerOptions": { + "composite": true, + "outDir": "../../build/cli", + "types": ["node"] + }, + "include": ["./"], + "references": [ + { "path": "../server" } + ] +} diff --git a/src/index.ts b/src/client/api.ts similarity index 85% rename from src/index.ts rename to src/client/api.ts index 2c2266e..a13ad69 100644 --- a/src/index.ts +++ b/src/client/api.ts @@ -1,15 +1,15 @@ -import WSClient from './WS/WSClient.js'; +import WSClient from './ws/WSClient.js'; import TestInitEvent from './event/TestInitEvent.js'; import TestDoneEvent from './event/TestDoneEvent.js'; -import type Route from './WS/route/Route.js'; -import type RouteRequest from './WS/route/RouteRequest.js'; -import type RouteHandler from './WS/route/RouteHandler.js'; +import type Route from './ws/route/Route.js'; +import type RouteRequest from './ws/route/RouteRequest.js'; +import type RouteHandler from './ws/route/RouteHandler.js'; import type { RouteMatcher, RouteHandlerCallback, RouteOptions, -} from './WS/route/RouteHandler.js'; +} from './ws/route/RouteHandler.js'; export { Route, diff --git a/src/event/TestDoneEvent.ts b/src/client/event/TestDoneEvent.ts similarity index 100% rename from src/event/TestDoneEvent.ts rename to src/client/event/TestDoneEvent.ts diff --git a/src/event/TestInitEvent.ts b/src/client/event/TestInitEvent.ts similarity index 100% rename from src/event/TestInitEvent.ts rename to src/client/event/TestInitEvent.ts diff --git a/src/client/runner.ts b/src/client/runner.ts new file mode 100644 index 0000000..aedcd3e --- /dev/null +++ b/src/client/runner.ts @@ -0,0 +1,55 @@ +/** + * Functions to be injected into the test page to control the client test runs. + * + * Keep these funcs self-contained so that they can be serialized and injected. + */ + +// No coverage support for this kind of functions yet +/* c8 ignore start */ + +/** + * Dispatches an init event after the test scripts are successfully imported. + */ +export const init = (uuid: string) => { + window.dispatchEvent(new CustomEvent(`__wrightplay_${uuid}_init__`)); +}; + +/** + * Injects the test script and resolves with the exit code. + */ +export const inject = (uuid: string) => ( + new Promise((resolve) => { + const script = document.createElement('script'); + + // Detect inject error + script.addEventListener('error', () => { + // eslint-disable-next-line no-console + console.error('Failed to inject test script'); + resolve(1); + }, { once: true }); + + // Detect init error + const onUncaughtError = () => { + // eslint-disable-next-line no-console + console.error('Uncaught error detected while initializing the tests'); + resolve(1); + }; + window.addEventListener('error', onUncaughtError, { once: true }); + + // Detect init end + window.addEventListener(`__wrightplay_${uuid}_init__`, () => { + window.removeEventListener('error', onUncaughtError); + }, { once: true }); + + // Detect test done + window.addEventListener(`__wrightplay_${uuid}_done__`, ({ exitCode }) => { + window.removeEventListener('error', onUncaughtError); + resolve(exitCode); + }, { once: true }); + + // Inject + script.src = '/stdin.js'; + script.type = 'module'; + document.head.append(script); + }) +); diff --git a/src/client/tsconfig.json b/src/client/tsconfig.json new file mode 100644 index 0000000..baef9d0 --- /dev/null +++ b/src/client/tsconfig.json @@ -0,0 +1,12 @@ +{ + "extends": "../../tsconfig.base.json", + "compilerOptions": { + "composite": true, + "lib": ["ESNext", "DOM"], + "outDir": "../../build/client" + }, + "include": ["./"], + "references": [ + { "path": "../common" } + ] +} diff --git a/src/WS/WSClient.ts b/src/client/ws/WSClient.ts similarity index 97% rename from src/WS/WSClient.ts rename to src/client/ws/WSClient.ts index 49b3abb..cee9e60 100644 --- a/src/WS/WSClient.ts +++ b/src/client/ws/WSClient.ts @@ -3,7 +3,7 @@ import { createRouteMeta, parseServerMeta, RouteServerMeta, -} from './message.js'; +} from '../../common/ws/message.js'; import RouteHandler, { RouteHandlerCallback, RouteMatcher, RouteOptions } from './route/RouteHandler.js'; import RouteRequest from './route/RouteRequest.js'; import Route from './route/Route.js'; @@ -80,7 +80,7 @@ export default class WSClient { return this.statusPromise; } - bypassFetch(...fetchArgs: Parameters) { + bypassFetch(...fetchArgs: Parameters) { const request = new Request(...fetchArgs); request.headers.set(`bypass-${this.uuid}`, 'true'); return fetch(request); diff --git a/src/WS/handle/HostHandle.ts b/src/client/ws/handle/HostHandle.ts similarity index 98% rename from src/WS/handle/HostHandle.ts rename to src/client/ws/handle/HostHandle.ts index ed014ed..4710aa8 100644 --- a/src/WS/handle/HostHandle.ts +++ b/src/client/ws/handle/HostHandle.ts @@ -3,8 +3,8 @@ import { parseServerMeta, HandleMetaBase, HandleClientMeta, -} from '../message.js'; -import * as Serializer from '../../serializer/index.js'; +} from '../../../common/ws/message.js'; +import * as Serializer from '../../../common/serializer/index.js'; export type Unboxed = Arg extends URL diff --git a/src/WS/route/Route.ts b/src/client/ws/route/Route.ts similarity index 98% rename from src/WS/route/Route.ts rename to src/client/ws/route/Route.ts index 5c6dbab..09885b2 100644 --- a/src/WS/route/Route.ts +++ b/src/client/ws/route/Route.ts @@ -1,4 +1,4 @@ -import { createRouteMeta, parseServerMeta } from '../message.js'; +import { createRouteMeta, parseServerMeta } from '../../../common/ws/message.js'; import type RouteRequest from './RouteRequest.js'; export type RouteChain = (done: boolean) => Promise; diff --git a/src/WS/route/RouteHandler.ts b/src/client/ws/route/RouteHandler.ts similarity index 97% rename from src/WS/route/RouteHandler.ts rename to src/client/ws/route/RouteHandler.ts index bf92a45..ee6b048 100644 --- a/src/WS/route/RouteHandler.ts +++ b/src/client/ws/route/RouteHandler.ts @@ -1,4 +1,4 @@ -import globToRegex from '../../util/globToRegex.js'; +import globToRegex from '../../../common/utils/globToRegex.js'; import type Route from './Route.js'; import type RouteRequest from './RouteRequest.js'; diff --git a/src/WS/route/RouteRequest.ts b/src/client/ws/route/RouteRequest.ts similarity index 98% rename from src/WS/route/RouteRequest.ts rename to src/client/ws/route/RouteRequest.ts index b6963e5..0b52677 100644 --- a/src/WS/route/RouteRequest.ts +++ b/src/client/ws/route/RouteRequest.ts @@ -1,6 +1,6 @@ import type playwright from 'playwright-core'; import HostHandle from '../handle/HostHandle.js'; -import { RouteRequestMeta } from '../message.js'; +import { RouteRequestMeta } from '../../../common/ws/message.js'; import { FallbackOverrides } from './Route.js'; export default class RouteRequest { diff --git a/src/common/globals.d.ts b/src/common/globals.d.ts new file mode 100644 index 0000000..ef65657 --- /dev/null +++ b/src/common/globals.d.ts @@ -0,0 +1,37 @@ +/** + * APIs that are common to Node.js and the DOM. + * + * Better if a lib provides these types. + * + * https://github.com/microsoft/TypeScript-DOM-lib-generator/issues/1402 + */ + +declare global { + interface URL { + hash: string; + host: string; + hostname: string; + href: string; + readonly origin: string; + password: string; + pathname: string; + port: string; + protocol: string; + search: string; + readonly searchParams: URLSearchParams; + username: string; + toString(): string; + toJSON(): string; + } + + interface URLConstructor { + new(input: string, base?: string | URL): URL; + createObjectURL(object: Blob): string; + revokeObjectURL(url: string): void; + readonly prototype: URL; + } + + const URL: typeof URLConstructor; +} + +export {}; diff --git a/src/serializer/Handle.ts b/src/common/serializer/Handle.ts similarity index 70% rename from src/serializer/Handle.ts rename to src/common/serializer/Handle.ts index 407b337..9794281 100644 --- a/src/serializer/Handle.ts +++ b/src/common/serializer/Handle.ts @@ -1,8 +1,5 @@ export default class Handle { constructor( - /** - * @internal - */ readonly id: number, ) {} } diff --git a/src/serializer/Serializable.ts b/src/common/serializer/Serializable.ts similarity index 100% rename from src/serializer/Serializable.ts rename to src/common/serializer/Serializable.ts diff --git a/src/serializer/index.ts b/src/common/serializer/index.ts similarity index 100% rename from src/serializer/index.ts rename to src/common/serializer/index.ts diff --git a/src/serializer/parseEvaluateExpression.ts b/src/common/serializer/parseEvaluateExpression.ts similarity index 100% rename from src/serializer/parseEvaluateExpression.ts rename to src/common/serializer/parseEvaluateExpression.ts diff --git a/src/serializer/parseSerializedValue.ts b/src/common/serializer/parseSerializedValue.ts similarity index 100% rename from src/serializer/parseSerializedValue.ts rename to src/common/serializer/parseSerializedValue.ts diff --git a/src/serializer/serializeValue.ts b/src/common/serializer/serializeValue.ts similarity index 100% rename from src/serializer/serializeValue.ts rename to src/common/serializer/serializeValue.ts diff --git a/src/common/tsconfig.json b/src/common/tsconfig.json new file mode 100644 index 0000000..2599b43 --- /dev/null +++ b/src/common/tsconfig.json @@ -0,0 +1,11 @@ +{ + "extends": "../../tsconfig.base.json", + "compilerOptions": { + "composite": true, + "lib": ["ES2022", "ESNext.Disposable"], + "module": "Node16", + "moduleResolution": "Node16", + "outDir": "../../build/common" + }, + "include": ["./"] +} diff --git a/src/util/globToRegex.ts b/src/common/utils/globToRegex.ts similarity index 100% rename from src/util/globToRegex.ts rename to src/common/utils/globToRegex.ts diff --git a/src/util/patchDisposable.ts b/src/common/utils/patchDisposable.ts similarity index 100% rename from src/util/patchDisposable.ts rename to src/common/utils/patchDisposable.ts diff --git a/src/WS/message.ts b/src/common/ws/message.ts similarity index 100% rename from src/WS/message.ts rename to src/common/ws/message.ts diff --git a/src/BrowserLogger.ts b/src/server/BrowserLogger.ts similarity index 100% rename from src/BrowserLogger.ts rename to src/server/BrowserLogger.ts diff --git a/src/CoverageReporter.ts b/src/server/CoverageReporter.ts similarity index 100% rename from src/CoverageReporter.ts rename to src/server/CoverageReporter.ts diff --git a/src/Runner.ts b/src/server/Runner.ts similarity index 90% rename from src/Runner.ts rename to src/server/Runner.ts index 867a3b8..220d3a6 100644 --- a/src/Runner.ts +++ b/src/server/Runner.ts @@ -11,12 +11,13 @@ import getPort, { portNumbers } from 'get-port'; import esbuild from 'esbuild'; import sirv from 'sirv'; -import './util/patchDisposable.js'; -import EventEmitter from './util/TypedEventEmitter.js'; +import '../common/utils/patchDisposable.js'; +import EventEmitter from './utils/TypedEventEmitter.js'; import TestFinder from './TestFinder.js'; import BrowserLogger from './BrowserLogger.js'; import CoverageReporter from './CoverageReporter.js'; -import WSServer from './WS/WSServer.js'; +import WSServer from './ws/WSServer.js'; +import * as clientRunner from '../client/runner.js'; export type BrowserTypeName = 'chromium' | 'firefox' | 'webkit'; @@ -262,9 +263,8 @@ export default class Runner implements Disposable { console.warn('No test file found'); } const importStatements = importFiles.map((file) => `import '${file}'`).join('\n'); - const initFunc = (uuid: string) => window.dispatchEvent(new CustomEvent(`__wrightplay_${uuid}_init__`)); return { - contents: `${importStatements}\n(${initFunc.toString()})('${this.uuid}')`, + contents: `${importStatements}\n(${clientRunner.init.toString()})('${this.uuid}')`, resolveDir: cwd, }; }); @@ -457,42 +457,7 @@ export default class Runner implements Disposable { const wsServer = new WSServer(this.uuid, fileServer, page); const run = async () => { await wsServer.reset(); - return page.evaluate((uuid) => ( - new Promise((resolve) => { - const script = document.createElement('script'); - - // Detect inject error - script.addEventListener('error', () => { - // eslint-disable-next-line no-console - console.error('Failed to inject test script'); - resolve(1); - }, { once: true }); - - // Detect init error - const onUncaughtError = () => { - // eslint-disable-next-line no-console - console.error('Uncaught error detected while initializing the tests'); - resolve(1); - }; - window.addEventListener('error', onUncaughtError, { once: true }); - - // Detect init end - window.addEventListener(`__wrightplay_${uuid}_init__`, () => { - window.removeEventListener('error', onUncaughtError); - }, { once: true }); - - // Detect test done - window.addEventListener(`__wrightplay_${uuid}_done__`, ({ exitCode }) => { - window.removeEventListener('error', onUncaughtError); - resolve(exitCode); - }, { once: true }); - - // Inject - script.src = '/stdin.js'; - script.type = 'module'; - document.head.append(script); - }) - ), this.uuid) + return page.evaluate(clientRunner.inject, this.uuid) .catch((error) => { // eslint-disable-next-line no-console console.error(error); diff --git a/src/TestFinder.ts b/src/server/TestFinder.ts similarity index 97% rename from src/TestFinder.ts rename to src/server/TestFinder.ts index 4dad723..1c75849 100644 --- a/src/TestFinder.ts +++ b/src/server/TestFinder.ts @@ -3,8 +3,8 @@ import path from 'node:path'; import { globby } from 'globby'; import globParent from 'glob-parent'; -import './util/patchDisposable.js'; -import EventEmitter from './util/TypedEventEmitter.js'; +import '../common/utils/patchDisposable.js'; +import EventEmitter from './utils/TypedEventEmitter.js'; export interface TestFinderOptions { patterns: string | readonly string[]; diff --git a/src/node.ts b/src/server/api.ts similarity index 100% rename from src/node.ts rename to src/server/api.ts diff --git a/src/server/tsconfig.json b/src/server/tsconfig.json new file mode 100644 index 0000000..2f2edc9 --- /dev/null +++ b/src/server/tsconfig.json @@ -0,0 +1,16 @@ +{ + "extends": "../../tsconfig.base.json", + "compilerOptions": { + "composite": true, + "lib": ["ES2022", "ESNext.Disposable"], + "module": "Node16", + "moduleResolution": "Node16", + "outDir": "../../build/server", + "types": ["node"] + }, + "include": ["./"], + "references": [ + { "path": "../common" }, + { "path": "../client" } + ] +} diff --git a/src/util/TypedEventEmitter.ts b/src/server/utils/TypedEventEmitter.ts similarity index 100% rename from src/util/TypedEventEmitter.ts rename to src/server/utils/TypedEventEmitter.ts diff --git a/src/WS/WSServer.ts b/src/server/ws/WSServer.ts similarity index 98% rename from src/WS/WSServer.ts rename to src/server/ws/WSServer.ts index 155e0b9..3439030 100644 --- a/src/WS/WSServer.ts +++ b/src/server/ws/WSServer.ts @@ -1,13 +1,13 @@ import type http from 'node:http'; import WebSocket, { WebSocketServer } from 'ws'; import type playwright from 'playwright'; -import * as Serializer from '../serializer/index.js'; +import * as Serializer from '../../common/serializer/index.js'; import { RouteClientMeta, HandleClientMeta, parseClientMeta, createRouteMeta, createHandleMeta, -} from './message.js'; +} from '../../common/ws/message.js'; /** * WebSocket Server that processes messages from the page client into Playwright actions diff --git a/src/tsconfig.json b/src/tsconfig.json new file mode 100644 index 0000000..bd075d0 --- /dev/null +++ b/src/tsconfig.json @@ -0,0 +1,13 @@ +{ + "extends": "../tsconfig.base.json", + "compilerOptions": { + "composite": true, + "outDir": "../build", + }, + "references": [ + { "path": "./cli" }, + { "path": "./client" }, + { "path": "./common" }, + { "path": "./server" } + ] +} diff --git a/test/default.setup.ts b/test/default.setup.ts index 48c0431..b734385 100644 --- a/test/default.setup.ts +++ b/test/default.setup.ts @@ -11,7 +11,7 @@ const { } = await (async () => { if (typeof window === 'undefined') return nodeMocha; - const { onInit, done } = await import('../src/index.js'); + const { onInit, done } = await import('../src/client/api.js'); mocha.setup({ ui: 'bdd', diff --git a/test/handle/basic.test.ts b/test/handle/basic.test.ts index f78bed1..748ea62 100644 --- a/test/handle/basic.test.ts +++ b/test/handle/basic.test.ts @@ -1,6 +1,6 @@ import { describe, it, expect } from '../default.setup.js'; -import HostHandle from '../../src/WS/handle/HostHandle.js'; -import { pageHandle } from '../../src/index.js'; +import HostHandle from '../../src/client/ws/handle/HostHandle.js'; +import { pageHandle } from '../../src/client/api.js'; describe('handle', () => { it('should evaluate', async () => { diff --git a/test/handle/cross-window.test.ts b/test/handle/cross-window.test.ts index 9a3e0da..94577de 100644 --- a/test/handle/cross-window.test.ts +++ b/test/handle/cross-window.test.ts @@ -1,5 +1,5 @@ import { describe, it, expect } from '../default.setup.js'; -import { pageHandle } from '../../src/index.js'; +import { pageHandle } from '../../src/client/api.js'; describe('cross window serialize', () => { let contentWindow: typeof window; diff --git a/test/route/basic.test.ts b/test/route/basic.test.ts index 81fe0a9..0d3c719 100644 --- a/test/route/basic.test.ts +++ b/test/route/basic.test.ts @@ -4,7 +4,7 @@ import { contextUnroute, bypassFetch, Route, -} from '../../src/index.js'; +} from '../../src/client/api.js'; describe('basic routing', () => { const float: Promise[] = []; diff --git a/test/serializer/basic.test.ts b/test/serializer/basic.test.ts index eaf4139..7dd4915 100644 --- a/test/serializer/basic.test.ts +++ b/test/serializer/basic.test.ts @@ -1,12 +1,12 @@ import { describe, expect, it } from '../default.setup.js'; -import Handle from '../../src/serializer/Handle.js'; +import Handle from '../../src/common/serializer/Handle.js'; import { SerializableValue, SerializedValue, serializeValue, noFallback, parseSerializedValue, -} from '../../src/serializer/index.js'; +} from '../../src/common/serializer/index.js'; describe('serializer', () => { function parse( @@ -114,7 +114,7 @@ describe('serializer', () => { }); it('should work for circular references', () => { - const arr: SerializableValue = [1, ['deep', { deeper: [] }]]; + const arr: SerializableValue[] = [1, ['deep', { deeper: [] }]]; arr.push(arr); expect(parse(arr)).toEqual(arr); }); diff --git a/test/third-party/mocha/setup.ts b/test/third-party/mocha/setup.ts index 8f634b4..0710f84 100644 --- a/test/third-party/mocha/setup.ts +++ b/test/third-party/mocha/setup.ts @@ -1,5 +1,5 @@ import 'mocha'; -import { onInit, done } from '../../../src/index.js'; +import { onInit, done } from '../../../src/client/api.js'; mocha.setup({ ui: 'bdd', diff --git a/test/third-party/tape/setup.ts b/test/third-party/tape/setup.ts index 41841b7..9af5263 100644 --- a/test/third-party/tape/setup.ts +++ b/test/third-party/tape/setup.ts @@ -1,5 +1,5 @@ import process from 'process'; -import { done } from '../../../src/index.js'; +import { done } from '../../../src/client/api.js'; globalThis.process = process; diff --git a/test/third-party/uvu/setup.ts b/test/third-party/uvu/setup.ts index bbcc56f..fe1adb0 100644 --- a/test/third-party/uvu/setup.ts +++ b/test/third-party/uvu/setup.ts @@ -3,7 +3,7 @@ * @see [Improve Programmatic Usage · Issue #113 · lukeed/uvu]{@link https://github.com/lukeed/uvu/issues/113} */ /* eslint-disable no-console */ -import { onInit, done } from '../../../src/index.js'; +import { onInit, done } from '../../../src/client/api.js'; let total: number | undefined; let passed: number | undefined; diff --git a/test/third-party/zora/setup.ts b/test/third-party/zora/setup.ts index bf369ce..5f6537a 100644 --- a/test/third-party/zora/setup.ts +++ b/test/third-party/zora/setup.ts @@ -1,6 +1,6 @@ /* eslint-disable no-restricted-syntax */ import { hold, report, createTAPReporter } from 'zora'; -import { done, onInit } from '../../../src/index.js'; +import { done, onInit } from '../../../src/client/api.js'; // Hold zora default run hold(); diff --git a/test/tsconfig.json b/test/tsconfig.json index 0b26517..72f7589 100644 --- a/test/tsconfig.json +++ b/test/tsconfig.json @@ -3,9 +3,13 @@ "compilerOptions": { "allowJs": true, "checkJs": true, + "composite": true, + "lib": ["ESNext", "DOM"], "noEmit": true, - "rootDir": "../", - "target": "ESNext" + "outDir": "../build/test" }, - "include": ["**/*", "../static/**/*"] + "include": ["./"], + "references": [ + { "path": "../src" } + ] } diff --git a/tsconfig.base.json b/tsconfig.base.json new file mode 100644 index 0000000..674d386 --- /dev/null +++ b/tsconfig.base.json @@ -0,0 +1,25 @@ +{ + "compilerOptions": { + "declaration": true, + "declarationMap": true, + "esModuleInterop": true, + "exactOptionalPropertyTypes": true, + "forceConsistentCasingInFileNames": true, + "lib": ["ESNext"], + "module": "ESNext", + "moduleResolution": "Bundler", + "outDir": "./build", + "skipLibCheck": true, + "sourceMap": true, + "strict": true, + "stripInternal": true, + "target": "ES2022", + "types": [], + "useDefineForClassFields": true + }, + "include": [], + "ts-node": { + "preferTsExts": true, + "transpileOnly": true + } +} diff --git a/tsconfig.json b/tsconfig.json index 834f33c..14d7739 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,26 +1,7 @@ -{ - "compilerOptions": { - "baseUrl": ".", - "declaration": true, - "declarationMap": true, - "esModuleInterop": true, - "exactOptionalPropertyTypes": true, - "forceConsistentCasingInFileNames": true, - "lib": ["ESNext", "DOM"], - "module": "ESNext", - "moduleResolution": "Bundler", - "outDir": "./build", - "rootDir": "./src", - "skipLibCheck": true, - "sourceMap": true, - "strict": true, - "stripInternal": true, - "target": "ES2019", - "useDefineForClassFields": true - }, - "include": ["./src"], - "ts-node": { - "preferTsExts": true, - "transpileOnly": true - } -} +{ + "extends": "./tsconfig.base.json", + "references": [ + { "path": "./src" }, + { "path": "./test" } + ] +}