Skip to content
Open
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
19 changes: 10 additions & 9 deletions packages/pharos/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,15 @@
"build:minify:html": "node ./scripts/build-minified-html.js",
"build:patches": "node ./scripts/build-patches.js",
"build:sassdoc": "node ./scripts/build-sassdoc.js",
"build:tests": "tsc --project tsconfig.json",
"build:replace": "replace-in-file \"/(import|from)( '[.]+/)(.*)(?<!.js)(';)/g\" \"\\$1\\$2\\$3.js\\$4\" \"lib/**/*.js, lib/**/*.d.ts\" --isRegex --verbose",
"build:replace:dynamic": "replace-in-file \"/(import[(])(.)([.]+/)(.*?)(?<!.js)(.[)])/g\" \"\\$1/* webpackChunkName: '[request]' */ \\$2\\$3\\$4.js\\$5\" \"lib/**/*.js\" --isRegex --verbose",
"build:replace:imports": "yarn build:replace && yarn build:replace:dynamic",
"prepublishOnly": "yarn build",
"clean": "rimraf lib src/react-components",
"pretest": "yarn prebuild && yarn build:styles && yarn build:tests && yarn build:replace:imports && yarn build:minify:html",
"test": "yarn pretest && wtr",
"test:watch": "wtr --watch"
"pretest": "yarn build:tokens && yarn build:styles && yarn test:typecheck",
"test": "yarn pretest && vitest run --coverage",
"test:watch": "yarn pretest && vitest",
"test:typecheck": "tsc --project tsconfig.test.json --noEmit"
},
"browserslist": [
"last 2 versions",
Expand Down Expand Up @@ -69,16 +69,16 @@
"devDependencies": {
"@custom-elements-manifest/analyzer": "^0.11.0",
"@open-wc/testing": "patch:@open-wc/testing@npm%3A4.0.0#~/.yarn/patches/@open-wc-testing-npm-4.0.0-96dbe4d202.patch",
"@types/mocha": "^10.0.10",
"@types/react": "^18.3.28",
"@types/react-dom": "^18.3.7",
"@web/test-runner": "^0.20.2",
"@web/test-runner-commands": "^0.9.0",
"@web/test-runner-playwright": "^0.11.1",
"@vitest/browser-playwright": "^4.1.8",
"@vitest/coverage-istanbul": "^4.1.8",
"@webcomponents/scoped-custom-element-registry": "^0.0.10",
"autoprefixer": "^10.5.0",
"chokidar": "^5.0.0",
"globby": "^16.2.0",
"minify-html-literals": "^1.3.5",
"playwright": "^1.60.0",
"postcss": "^8.5.15",
"prettier": "^3.8.3",
"react": "^18.3.1",
Expand All @@ -89,7 +89,8 @@
"sinon": "^22.0.0",
"style-dictionary": "^5.4.3",
"ts-lit-plugin": "^2.0.2",
"typescript": "^6.0.3"
"typescript": "^6.0.3",
"vitest": "^4.1.8"
},
"customElements": "custom-elements.json",
"exports": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,9 @@ describe('pharos-checkbox-group', () => {
.querySelector('fieldset')
?.getAttribute('aria-describedby');

expect(component.renderRoot.querySelector(`#${groupDescID}`)?.textContent)?.to.equal(text);
expect(component.renderRoot.querySelector(`#${groupDescID}`)?.textContent?.trim())?.to.equal(

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because of the difference in how vitest compiles the component for testing, there were some whitespace changes, which resulted in errors like this

AssertionError: expected '\n            Please make a selection\n            \n          ' to equal 'Please make a selection'

I just added .trim() where this was happening

text
);
});

it('updates the state of its children', async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ describe('pharos-coach-mark', () => {
);
});

before(() => {
beforeAll(() => {
logSpy = sinon.spy(console, 'error');
});

after(() => {
afterAll(() => {
logSpy.restore();
});

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { fixture, expect, aTimeout, elementUpdated } from '@open-wc/testing';
import { html } from 'lit/static-html.js';
import { sendKeys } from '@web/test-runner-commands';

import type { PharosImageCard } from './pharos-image-card';
import type { PharosButton } from '../button/pharos-button';
Expand Down Expand Up @@ -812,7 +811,6 @@ describe('pharos-image-card', () => {
);

component.focus();
sendKeys({ press: 'Tab' });

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was never actually doing anything meaningful, I removed just this line on develop as well and the test passes just the same.

const checkboxElement = component.renderRoot.querySelector(
'[data-pharos-component="PharosCheckbox"]'
);
Expand Down
8 changes: 5 additions & 3 deletions packages/pharos/src/components/pill/pharos-pill.test.ts

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These tests passed intermittently as they were when I was running them locally, extending the timeout made them less flaky

Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,8 @@ describe('PharosPill', () => {
// Wait for icon to load asynchronously
await waitUntil(
() => component.renderRoot?.querySelector('svg') !== null,
'Icon should be rendered'
'Icon should be rendered',
{ timeout: 5000 }
);

const icon = component.renderRoot?.querySelector('svg') as SVGSVGElement;
Expand All @@ -167,7 +168,8 @@ describe('PharosPill', () => {
// Wait for icon to load asynchronously
await waitUntil(
() => component.renderRoot?.querySelector('svg') !== null,
'Icon should be rendered'
'Icon should be rendered',
{ timeout: 5000 }
);

const icon = component.renderRoot?.querySelector('svg') as SVGSVGElement | null;
Expand Down Expand Up @@ -199,7 +201,7 @@ describe('PharosPill', () => {
await component.updateComplete;

// Wait for error to be caught
await waitUntil(() => caughtError !== null, 'Error should be caught');
await waitUntil(() => caughtError !== null, 'Error should be caught', { timeout: 5000 });

expect(caughtError!.message).to.equal('Could not get icon named "invalid-icon"');
} finally {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ describe('pharos-popover', () => {
`);
});

before(() => {
beforeAll(() => {
logSpy = sinon.spy(console, 'error');
});

after(() => {
afterAll(() => {
logSpy.restore();
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,9 @@ describe('pharos-radio-group', () => {
.querySelector('fieldset')
?.getAttribute('aria-describedby');

expect(component.renderRoot.querySelector(`#${groupDescID}`)?.textContent)?.to.equal(text);
expect(component.renderRoot.querySelector(`#${groupDescID}`)?.textContent?.trim())?.to.equal(
text
);
});

it("stops propagation of its child's change event", async () => {
Expand Down
4 changes: 2 additions & 2 deletions packages/pharos/src/components/sheet/pharos-sheet.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ describe('pharos-sheet', () => {
`);
});

before(() => {
beforeAll(() => {
logSpy = sinon.spy(console, 'error');
});

after(() => {
afterAll(() => {
logSpy.restore();
});

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { fixture, expect } from '@open-wc/testing';
import { html } from 'lit/static-html.js';
import { setViewport } from '@web/test-runner-commands';
import { page } from 'vitest/browser';

import type { PharosSidenav } from './pharos-sidenav';
import type { PharosButton } from '../button/pharos-button';
Expand Down Expand Up @@ -67,7 +67,7 @@ describe('pharos-sidenav', () => {
};

beforeEach(async () => {
await setViewport({ width: 1440, height: 900 });
await page.viewport(1440, 900);
component = await fixture(html`
<test-pharos-sidenav has-close-button open>
<test-pharos-link slot="top" href="/" id="jstor-logo">JSTOR</test-pharos-link>
Expand Down
2 changes: 1 addition & 1 deletion packages/pharos/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
"noImplicitOverride": true,
"useDefineForClassFields": false,
"skipLibCheck": true,
"types": ["mocha", "node"],
"types": ["vitest/globals", "node"],
"plugins": [
{
"name": "ts-lit-plugin",
Expand Down
11 changes: 11 additions & 0 deletions packages/pharos/tsconfig.test.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"extends": "./tsconfig.json",
"exclude": [
"src/pages/**",
"**/storyArgs.ts",
"src/**/*.stories.ts",
"src/**/*.stories.tsx",
"src/react-components/**",
"src/utils/_storybook/**"
]
}
74 changes: 74 additions & 0 deletions packages/pharos/vitest.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
import { fileURLToPath } from 'node:url';
import { defineConfig } from 'vitest/config';
import { playwright } from '@vitest/browser-playwright';

const silencedLogs = ['Lit is in dev mode.', 'Multiple versions of Lit loaded.'];

// Pre-existing unhandled rejections that wtr ignored, which we can now see and are silencing until resolved.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can add a follow-up issue to address these

const ignoredUnhandledErrors = [
'is not a valid preset', // image-card
'Could not get icon named', // icon
'Table must have an accessible name', // table
'Axe is already running', // coach-mark
];

// Stub unused web-test-runner-commands so @open-wc/testing's static import of it doesn't break the tests
const testRunnerCommandsStub = fileURLToPath(
new URL('./vitest.stubs/web-test-runner-commands.ts', import.meta.url)
);

export default defineConfig({
server: {
// Icons load via dynamic import, by pre-transforming them, they are available immediately and don't cause random test timeouts.
warmup: {
clientFiles: ['./src/styles/icons/*.ts'],
},
},
resolve: {
alias: {
'@web/test-runner-commands': testRunnerCommandsStub,
},
},
test: {
include: ['src/**/*.test.ts'],
globals: true,
setupFiles: ['./vitest.setup.ts'],
onConsoleLog(log) {
if (silencedLogs.some((l) => log.includes(l))) return false;
},
onUnhandledError(error) {
if (ignoredUnhandledErrors.some((m) => error.message?.includes(m))) return false;
},
coverage: {
// istanbul is the only provider that supports coverage while running against multiple browsers.
provider: 'istanbul',
include: ['src/**/*.ts'],
exclude: [
'src/**/*.test.ts',
'src/test/**',
'src/**/*.stories.*',
'src/**/storyArgs.ts',
'src/styles/**',
'src/react-components/**',
'src/pages/**',
'**/*.css.ts',
'**/*.tsx',
'src/utils/_storybook/**',
],
thresholds: {
statements: 94,
branches: 85,
functions: 96,
lines: 94,
},
},
browser: {
enabled: true,
headless: true,
provider: playwright(),
screenshotFailures: false,
viewport: { width: 1280, height: 720 },

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Match wtr's full-page size, Vitest iframe default is 414x896

instances: [{ browser: 'chromium' }, { browser: 'firefox' }, { browser: 'webkit' }],
},
},
});
5 changes: 5 additions & 0 deletions packages/pharos/vitest.setup.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// Polyfill for custom-element definitions.
import '@webcomponents/scoped-custom-element-registry';

// Register every Pharos component under the `test-` prefix
import './src/test/initComponents';
37 changes: 37 additions & 0 deletions packages/pharos/vitest.stubs/web-test-runner-commands.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// Stub for `@web/test-runner-commands` needed under Vitest browser mode.
//
// `@open-wc/semantic-dom-diff` (pulled in transitively by `@open-wc/testing`'s
// `expect`) statically imports `@web/test-runner-commands`, which itself imports
// a wtr-only websocket module (`__web-dev-server__web-socket.js`) that does not
// exist under Vite — breaking the whole `@open-wc/testing` import chain even
// though our tests never uses snapshot/dom-diff/command assertions.
//
// These exports mirror `@web/test-runner-commands` so the import resolves; each
// throws only if actually invoked. Aliased in `vitest.config.ts` so Vite's
// dep optimizer (which pre-bundles `@open-wc/testing`) picks it up.

const unavailable =
(name: string) =>
(..._args: unknown[]): never => {
throw new Error(`@web/test-runner-commands.${name} is not available under Vitest browser mode`);
};

export const executeServerCommand = unavailable('executeServerCommand');
export const setViewport = unavailable('setViewport');
export const emulateMedia = unavailable('emulateMedia');
export const setUserAgent = unavailable('setUserAgent');
export const sendKeys = unavailable('sendKeys');
export const selectOption = unavailable('selectOption');
export const sendMouse = unavailable('sendMouse');
export const resetMouse = unavailable('resetMouse');
export const a11ySnapshot = unavailable('a11ySnapshot');
export const writeFile = unavailable('writeFile');
export const readFile = unavailable('readFile');
export const removeFile = unavailable('removeFile');
export const findAccessibilityNode = unavailable('findAccessibilityNode');
export const getSnapshotConfig = unavailable('getSnapshotConfig');
export const getSnapshots = unavailable('getSnapshots');
export const getSnapshot = unavailable('getSnapshot');
export const saveSnapshot = unavailable('saveSnapshot');
export const removeSnapshot = unavailable('removeSnapshot');
export const compareSnapshot = unavailable('compareSnapshot');
57 changes: 0 additions & 57 deletions packages/pharos/web-test-runner.config.mjs

This file was deleted.

Loading
Loading