Skip to content

Commit

Permalink
test: use specific error messages for specific browsers
Browse files Browse the repository at this point in the history
  • Loading branch information
hunterloftis committed Apr 27, 2023
1 parent 4a164cf commit 07e5019
Show file tree
Hide file tree
Showing 7 changed files with 44 additions and 53 deletions.
5 changes: 0 additions & 5 deletions packages/accordion/test/accordion-item.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import { spy } from 'sinon';
import '@spectrum-web-components/accordion/sp-accordion-item.js';
import { AccordionItem } from '@spectrum-web-components/accordion/src/AccordionItem.js';
import { sendKeys } from '@web/test-runner-commands';
import { warnsOnDoubleRegister } from '../../../test/testing-helpers.js';

describe('Accordion Item', () => {
it('can exist with no parent accessibly', async () => {
Expand Down Expand Up @@ -197,8 +196,4 @@ describe('Accordion Item', () => {
expect(closed).to.be.false;
expect(el.open).to.be.true;
});
describe(
'dev mode registration',
warnsOnDoubleRegister(() => import('../sp-accordion-item.js'))
);
});
9 changes: 1 addition & 8 deletions packages/accordion/test/accordion.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,7 @@ import { Default } from '../stories/accordion.stories.js';
import { Accordion, AccordionItem } from '@spectrum-web-components/accordion';
import { sendKeys } from '@web/test-runner-commands';
import { spy } from 'sinon';
import {
testForLitDevWarnings,
warnsOnDoubleRegister,
} from '../../../test/testing-helpers.js';
import { testForLitDevWarnings } from '../../../test/testing-helpers.js';

describe('Accordion', () => {
testForLitDevWarnings(async () => await fixture<Accordion>(Default()));
Expand Down Expand Up @@ -321,8 +318,4 @@ describe('Accordion', () => {
expect(typeof outsideFocused).not.to.equal(AccordionItem);
expect(typeof outsideFocused).not.to.equal(Accordion);
});
describe(
'dev mode registration',
warnsOnDoubleRegister(() => import('../sp-accordion.js'))
);
});
9 changes: 1 addition & 8 deletions packages/action-bar/test/action-bar.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,7 @@ import { elementUpdated, expect, fixture, html } from '@open-wc/testing';
import '@spectrum-web-components/action-bar/sp-action-bar.js';
import { ActionBar } from '@spectrum-web-components/action-bar';
import { Default } from '../stories/action-bar.stories.js';
import {
testForLitDevWarnings,
warnsOnDoubleRegister,
} from '../../../test/testing-helpers.js';
import { testForLitDevWarnings } from '../../../test/testing-helpers.js';

describe('ActionBar', () => {
testForLitDevWarnings(async () => await fixture<ActionBar>(Default()));
Expand Down Expand Up @@ -91,8 +88,4 @@ describe('ActionBar', () => {
expect(el.variant).to.equal('fixed');
expect(el.getAttribute('variant')).to.equal('fixed');
});
describe(
'dev mode registration',
warnsOnDoubleRegister(() => import('../sp-action-bar.js'))
);
});
9 changes: 1 addition & 8 deletions packages/action-button/test/action-button.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,7 @@ import {
} from '@open-wc/testing';
import { sendKeys } from '@web/test-runner-commands';
import { spy } from 'sinon';
import {
testForLitDevWarnings,
warnsOnDoubleRegister,
} from '../../../test/testing-helpers.js';
import { testForLitDevWarnings } from '../../../test/testing-helpers.js';
import { m as BlackActionButton } from '../stories/action-button-black.stories.js';

describe('ActionButton', () => {
Expand Down Expand Up @@ -238,8 +235,4 @@ describe('ActionButton', () => {
expect(el.selected).to.be.true;
expect(button.getAttribute('aria-pressed')).to.equal('true');
});
describe(
'dev mode registration',
warnsOnDoubleRegister(() => import('../sp-action-button.js'))
);
});
5 changes: 0 additions & 5 deletions packages/action-group/test/action-group.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ import {
endEvent,
homeEvent,
testForLitDevWarnings,
warnsOnDoubleRegister,
} from '../../../test/testing-helpers';
import { sendKeys } from '@web/test-runner-commands';
import '@spectrum-web-components/action-group/sp-action-group.js';
Expand Down Expand Up @@ -1069,8 +1068,4 @@ describe('ActionGroup', () => {
expect(el.selected.length).to.equal(1);
expect(el.selected[0]).to.equal('Third');
});
describe(
'dev mode registration',
warnsOnDoubleRegister(() => import('../sp-action-group.js'))
);
});
9 changes: 1 addition & 8 deletions packages/action-menu/test/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,7 @@ import {
html,
oneEvent,
} from '@open-wc/testing';
import {
testForLitDevWarnings,
warnsOnDoubleRegister,
} from '../../../test/testing-helpers';
import { testForLitDevWarnings } from '../../../test/testing-helpers';

import { spy } from 'sinon';

Expand Down Expand Up @@ -426,8 +423,4 @@ export const testActionMenu = (mode: 'sync' | 'async'): void => {
expect(selectedItem.selected).to.be.true;
});
});
describe(
'dev mode registration',
warnsOnDoubleRegister(() => import('../sp-action-menu.js'))
);
};
51 changes: 40 additions & 11 deletions tools/base/test/define-element.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,34 +12,63 @@ governing permissions and limitations under the License.

import { expect } from '@open-wc/testing';
import { stub } from 'sinon';
import {
isFirefox,
isWebKit,
} from '@spectrum-web-components/shared/src/platform.js';

// for window.__swc
import '@spectrum-web-components/base';

const elements = [
{
name: 'sp-color-area',
register: () =>
import('@spectrum-web-components/color-area/sp-color-area.js'),
},
];
const elements = {
'sp-accordion-item': () =>
import('@spectrum-web-components/accordion/sp-accordion-item.js'),
'sp-accordion': () =>
import('@spectrum-web-components/accordion/sp-accordion.js'),
'sp-action-bar': () =>
import('@spectrum-web-components/action-bar/sp-action-bar.js'),
'sp-action-menu': () =>
import('@spectrum-web-components/action-menu/sp-action-menu.js'),
'sp-action-button': () =>
import('@spectrum-web-components/action-button/sp-action-button.js'),
'sp-action-group': () =>
import('@spectrum-web-components/action-group/sp-action-group.js'),
'sp-color-area': () =>
import('@spectrum-web-components/color-area/sp-color-area.js'),
};

const isSafari = /^((?!chrome|android).)*safari/i.test(navigator.userAgent);
const browser: 'webkit' | 'firefox' | 'chromium' = isWebKit()
? 'webkit'
: isFirefox()
? 'firefox'
: 'chromium';

describe('define-element', function () {
// registrations are globally-unique, so retries will always fail
this.retries(0);

beforeEach(function () {
window.__swc.verbose = true;
this.warn = stub(console, 'warn');
});

afterEach(function () {
this.warn.resetHistory();
window.__swc.verbose = false;
this.warn.restore();
});
elements.map(({ name, register }) =>
it('warns on redefinition', async function () {
const error = isSafari ? 'same tag name' : 'has already been';

Object.entries(elements).forEach(([name, register]) =>
it(`'${name}' warns on redefinition`, async function () {
// classes already-defined via transitive dependencies can't be tested this way
if (customElements.get(name)) {
this.skip();
}
const error = {
webkit: 'Cannot define multiple custom elements with the same tag name',
firefox: `'${name}' has already been defined`,
chromium: `"${name}" has already been used with this registry`,
}[browser];
let caughtError: Error | undefined;

customElements.define(name, class extends HTMLElement {});
Expand Down

0 comments on commit 07e5019

Please sign in to comment.