Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -69,5 +69,8 @@ jobs:
- name: Setup node
uses: ./.github/actions/setup-node

- name: Install playwright dependencies
run: yarn playwright install --with-deps chromium

- name: Run test
run: yarn test
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,7 @@ tsconfig*.tsbuildinfo
npm-debug.log*
yarn-debug.log*
yarn-error.log*

# Vitest browser test attachments (screenshots, traces)
.vitest-attachments
**/__screenshots__
11 changes: 11 additions & 0 deletions .oxlintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,16 @@
"plugins": ["eslint", "import", "oxc", "react", "typescript"],
"categories": {
"correctness": "error"
},
"rules": {
"eslint/no-unused-vars": [
"error",
{
"caughtErrors": "none",
"argsIgnorePattern": "^_",
"varsIgnorePattern": "^_",
"destructuredArrayIgnorePattern": "^_"
}
]
}
}
14 changes: 0 additions & 14 deletions jest.config.ts

This file was deleted.

14 changes: 6 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@
"lint": "yarn oxlint",
"precommit": "lint-staged",
"publish": "yarn build && yarn npm publish",
"test": "jest --ci",
"test:watch": "yarn test --watch",
"test": "vitest run",
"test:watch": "vitest",
"types": "tsc --noEmit"
},
"peerDependencies": {
Expand All @@ -59,20 +59,18 @@
},
"devDependencies": {
"@arethetypeswrong/core": "^0.18.2",
"@types/jest": "^30.0.0",
"@types/node": "^24.0.0",
"@types/react": "^19.0.0",
"jest": "^30.3.0",
"jest-environment-jsdom": "^30.3.0",
"jest-watch-typeahead": "^3.0.1",
"@vitest/browser-playwright": "^4.1.5",
"lint-staged": "^16.4.0",
"oxfmt": "^0.38.0",
"oxlint": "^1.53.0",
"oxlint-tsgolint": "^0.16.0",
"playwright": "^1.49.0",
"publint": "^0.3.18",
"ts-jest": "^29.4.9",
"tsdown": "^0.21.10",
"typescript": "^6.0.2",
"unplugin-unused": "^0.5.7"
"unplugin-unused": "^0.5.7",
"vitest": "^4.1.5"
}
}
6 changes: 3 additions & 3 deletions src/client/__tests__/initialize.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ describe('initialize', () => {
beforeAll(() => {
originalAddEventListener = window.addEventListener;
originalRemoveEventListener = window.removeEventListener;
window.addEventListener = jest.fn();
window.removeEventListener = jest.fn();
window.addEventListener = vi.fn();
window.removeEventListener = vi.fn();
});

beforeEach(() => {
jest.resetAllMocks();
vi.resetAllMocks();
});

it('should initialize and be destroyable', () => {
Expand Down
18 changes: 14 additions & 4 deletions src/client/initialize.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,20 @@ export function initialize<T = {}>(): PluginInstance<T> {
[event: string]: Function[];
} = {};

for (const [key, value] of new URL(
document.location.toString(),
).searchParams.entries())
pluginConfig[key] = JSON.parse(value);
const location = new URL(document.location.href);
for (const [key, value] of location.searchParams.entries()) {
try {
pluginConfig[key] = JSON.parse(value);
} catch (_err: unknown) {
if (__VITEST_BROWSER__ && (key === 'frameId' || key === 'sessionId')) {
// noop: vitest browser injects these into the test iframe URL
} else {
console.error(
`Failed to parse URL param ${key} with value ${value} as JSON.`,
);
}
}
}

const listener = (e: PluginMessageResponse) => {
emit(e.data.type, e.data.result, e.data.error);
Expand Down
1 change: 1 addition & 0 deletions src/globals.d.ts
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
declare const __VERSION__: string;
declare const __VITEST_BROWSER__: boolean;
4 changes: 2 additions & 2 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"esModuleInterop": true,
"forceConsistentCasingInFileNames": true,
"skipLibCheck": true,
"types": ["jest"]
"types": ["vitest/globals"]
},
"include": ["src", "jest.config.ts", "tsdown.config.ts"]
"include": ["src", "vitest.config.ts", "tsdown.config.ts"]
}
1 change: 1 addition & 0 deletions tsdown.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ export default defineConfig({

define: {
__VERSION__: JSON.stringify(packageJson.version),
__VITEST_BROWSER__: false.toString(),
},

publint: true,
Expand Down
21 changes: 21 additions & 0 deletions vitest.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { playwright } from '@vitest/browser-playwright';
import { defineConfig } from 'vitest/config';

import packageJson from './package.json' with { type: 'json' };

export default defineConfig({
define: {
__VERSION__: JSON.stringify(packageJson.version),
__VITEST_BROWSER__: true.toString(),
},
test: {
globals: true,
include: ['src/**/*.test.{js,jsx,ts,tsx}'],
browser: {
enabled: true,
provider: playwright(),
headless: true,
instances: [{ browser: 'chromium' }],
},
},
});
Loading