feat: add type definition files for testing

This commit is contained in:
Thomas Allmer
2019-08-06 01:06:36 +02:00
parent 53579c2731
commit 462a29f6bb
17 changed files with 170 additions and 4 deletions

View File

@@ -14,7 +14,7 @@ jobs:
<<: *defaults
steps:
- checkout
# Download and cache dependencies
# Download and cache dependencies
- restore_cache:
keys:
- v3-dependencies-{{ checksum "package.json" }}
@@ -29,6 +29,9 @@ jobs:
# build what needs to be build so we can use it in the next steps
- run: npm run build
# auto build typescript definition files (not part of build as locally JsDoc alone is all we need)
- run: npm run build:types
# run lint
- run: npm run lint
@@ -48,7 +51,7 @@ jobs:
at: ~/repo
- add_ssh_keys:
fingerprints:
- "3f:ea:54:b7:77:13:b6:cf:29:90:2b:19:bb:eb:b5:f1"
- '3f:ea:54:b7:77:13:b6:cf:29:90:2b:19:bb:eb:b5:f1'
- run:
name: Authenticate with registry
command: echo "//registry.npmjs.org/:_authToken=$NPM_TOKEN" >> ~/.npmrc

View File

@@ -4,6 +4,7 @@
"license": "MIT",
"scripts": {
"build": "lerna run build",
"build:types": "tsc -p tsconfig.build.types.json",
"lint": "run-p lint:*",
"lint:eslint": "eslint --ext .js,.html .",
"lint:prettier": "prettier \"**/*.js\" --list-different || (echo '↑↑ these files are not prettier formatted ↑↑' && exit 1)",
@@ -56,7 +57,7 @@
"lint-staged": "^9.2.0",
"npm-run-all": "4.1.3",
"prettier": "^1.18.2",
"typescript": "^3.3.3333",
"typescript-temporary-fork-for-jsdoc": "^3.6.0-insiders.20190802",
"vuepress": "^1.0.0-alpha.30",
"webpack-merge": "^4.1.5"
}

View File

@@ -0,0 +1,12 @@
/// <reference types="chai" />
declare namespace Chai {
interface Assertion {
accessible(options?: Object): Assertion;
}
interface Assert {
isAccessible(fixture: any, options?: Object): Assertion;
isNotAccessible(fixture: any, options?: Object): Assertion;
}
}

1
packages/chai-a11y-axe/index.d.ts vendored Normal file
View File

@@ -0,0 +1 @@
export { chaiA11yAxe } from "./src/accessible.js";

View File

@@ -0,0 +1,7 @@
/// <reference path="../chai-a11y-axe-plugin.d.ts" />
/**
* @param {any} chai
* @param {any} utils
*/
export const chaiA11yAxe: (chai: any, utils: any) => void;

View File

@@ -0,0 +1,17 @@
/// <reference types="chai" />
declare namespace Chai {
interface Assertion {
dom: Assertion;
lightDom: Assertion;
shadowDom: Assertion;
equalSnapshot(options?: Object): Assertion;
}
interface Assert {
dom: Assertion;
lightDom: Assertion;
shadowDom: Assertion;
equalSnapshot(fixture: any, options?: Object): Assertion;
}
}

View File

@@ -0,0 +1,7 @@
/// <reference path="chai-dom-diff-plugin.d.ts" />
/**
* @param {any} chai
* @param {any} utils
*/
export const chaiDomDiff: (chai: any, utils: any) => void;

3
packages/semantic-dom-diff/index.d.ts vendored Normal file
View File

@@ -0,0 +1,3 @@
export { chaiDomDiff } from "./chai-dom-diff.js";
import { getDiffableHTML } from "./get-diffable-html.js";
export { getDiffableHTML, getDiffableHTML as getDiffableSemanticHTML };

View File

@@ -0,0 +1,13 @@
/// <reference path="../chai-dom-diff-plugin.d.ts" />
import chai from 'chai';
type expect = typeof chai.expect;
type assert = typeof chai.assert;
type should = typeof chai.should;
declare function expect(...args: Parameters<expect>): ReturnType<expect>;
declare const assert: assert;
declare function should(...args: Parameters<should>): ReturnType<should>;
export { expect, assert, should };

View File

@@ -10,7 +10,9 @@ describe('dom', () => {
it('passes along provided configuration', async () => {
const el = await fixture('<div foo="bar"></div>');
// @ts-ignore
expect(el).dom.to.equal('<div></div>', { ignoreAttributes: ['foo'] });
// @ts-ignore
assert.dom.equal(el, '<div></div>', { ignoreAttributes: ['foo'] });
});
});
@@ -24,7 +26,9 @@ describe('lightDom', () => {
it('passes along provided configuration', async () => {
const el = await fixture('<div><p foo="bar">foo</p></div>');
// @ts-ignore
expect(el).lightDom.to.equal('<p>foo</p>', { ignoreAttributes: ['foo'] });
// @ts-ignore
assert.lightDom.equal(el, '<p>foo</p>', { ignoreAttributes: ['foo'] });
});
});

View File

@@ -0,0 +1,11 @@
import chai from 'chai';
type expect = typeof chai.expect;
type assert = typeof chai.assert;
type should = typeof chai.should;
declare function expect(...args: Parameters<expect>): ReturnType<expect>;
declare const assert: assert;
declare function should(...args: Parameters<should>): ReturnType<should>;
export { expect, assert, should };

View File

@@ -0,0 +1,26 @@
export { html } from '@open-wc/testing-helpers/index-no-side-effects.js';
export { unsafeStatic } from '@open-wc/testing-helpers/index-no-side-effects.js';
export { triggerBlurFor } from '@open-wc/testing-helpers/index-no-side-effects.js';
export { triggerFocusFor } from '@open-wc/testing-helpers/index-no-side-effects.js';
export { oneEvent } from '@open-wc/testing-helpers/index-no-side-effects.js';
export { isIE } from '@open-wc/testing-helpers/index-no-side-effects.js';
export { defineCE } from '@open-wc/testing-helpers/index-no-side-effects.js';
export { aTimeout } from '@open-wc/testing-helpers/index-no-side-effects.js';
export { litFixture } from '@open-wc/testing-helpers/index-no-side-effects.js';
export { litFixtureSync } from '@open-wc/testing-helpers/index-no-side-effects.js';
export { fixture } from '@open-wc/testing-helpers/index-no-side-effects.js';
export { fixtureSync } from '@open-wc/testing-helpers/index-no-side-effects.js';
export { fixtureCleanup } from '@open-wc/testing-helpers/index-no-side-effects.js';
export { elementUpdated } from '@open-wc/testing-helpers/index-no-side-effects.js';
import chai from 'chai';
type expect = typeof chai.expect;
type assert = typeof chai.assert;
type should = typeof chai.should;
declare function expect(...args: Parameters<expect>): ReturnType<expect>;
declare const assert: assert;
declare function should(...args: Parameters<should>): ReturnType<should>;
export { expect, assert, should };

27
packages/testing/index.d.ts vendored Normal file
View File

@@ -0,0 +1,27 @@
export { html } from '@open-wc/testing-helpers/index.js';
export { unsafeStatic } from '@open-wc/testing-helpers/index.js';
export { triggerBlurFor } from '@open-wc/testing-helpers/index.js';
export { triggerFocusFor } from '@open-wc/testing-helpers/index.js';
export { oneEvent } from '@open-wc/testing-helpers/index.js';
export { isIE } from '@open-wc/testing-helpers/index.js';
export { defineCE } from '@open-wc/testing-helpers/index.js';
export { aTimeout } from '@open-wc/testing-helpers/index.js';
export { nextFrame } from '@open-wc/testing-helpers/index.js';
export { litFixture } from '@open-wc/testing-helpers/index.js';
export { litFixtureSync } from '@open-wc/testing-helpers/index.js';
export { fixture } from '@open-wc/testing-helpers/index.js';
export { fixtureSync } from '@open-wc/testing-helpers/index.js';
export { fixtureCleanup } from '@open-wc/testing-helpers/index.js';
export { elementUpdated } from '@open-wc/testing-helpers/index.js';
import chai from 'chai';
type expect = typeof chai.expect;
type assert = typeof chai.assert;
type should = typeof chai.should;
declare function expect(...args: Parameters<expect>): ReturnType<expect>;
declare const assert: assert;
declare function should(...args: Parameters<should>): ReturnType<should>;
export { expect, assert, should };

View File

@@ -0,0 +1 @@
export {};

View File

@@ -1,11 +1,16 @@
import { fixture, expect } from '../index.js';
describe('Plugin: semantic-dom-diff', () => {
it('can semantically compare dom trees', async () => {
it('can semantically compare full dom trees', async () => {
const el = await fixture(`<div><!-- comment --><h1>${'Hey'} </h1> </div>`);
expect(el).dom.to.equal('<div><h1>Hey</h1></div>');
});
it('can semantically compare lightDom trees', async () => {
const el = await fixture(`<div><!-- comment --><h1>${'Hey'} </h1> </div>`);
expect(el).lightDom.to.equal('<h1>Hey</h1>');
});
it('can compare against a snapshot', async () => {
const el = await fixture(`<div><!-- comment --><h1>${'Hey'} </h1> </div>`);
expect(el).dom.to.equalSnapshot();

23
tsconfig.build.types.json Normal file
View File

@@ -0,0 +1,23 @@
{
"compilerOptions": {
"target": "esnext",
"module": "esnext",
"moduleResolution": "node",
"lib": ["es2017", "dom"],
"declaration": true,
"allowJs": true,
"checkJs": true,
"emitDeclarationOnly": true,
"strict": false,
"noImplicitThis": true,
"alwaysStrict": true,
"types": ["node", "mocha", "chai"],
"esModuleInterop": true
},
"files": ["browser.d.ts"],
"include": [
"packages/testing-helpers/*.js",
"packages/semantic-dom-diff/get-diffable-html.js",
"packages/semantic-dom-diff/src/utils.js"
]
}

View File

@@ -15703,6 +15703,11 @@ typeface-oswald@0.0.54:
resolved "https://registry.yarnpkg.com/typeface-oswald/-/typeface-oswald-0.0.54.tgz#1e253011622cdd50f580c04e7d625e7f449763d7"
integrity sha512-U1WMNp4qfy4/3khIfHMVAIKnNu941MXUfs3+H9R8PFgnoz42Hh9pboSFztWr86zut0eXC8byalmVhfkiKON/8Q==
typescript-temporary-fork-for-jsdoc@^3.6.0-insiders.20190802:
version "3.6.0-insiders.20190802"
resolved "https://registry.yarnpkg.com/typescript-temporary-fork-for-jsdoc/-/typescript-temporary-fork-for-jsdoc-3.6.0-insiders.20190802.tgz#aece6f3f5d53c6e06e5e1c4af5a19183d7124ab6"
integrity sha512-j76opNh6ljAXDUDXr03+pOkITiATPbUlQlMp9pxD/SR3eNKAtIdHwOTf3dDspyGs8TGJQjQXMUiYqJr0gW+nCg==
typescript@^3.3.3333:
version "3.5.3"
resolved "https://registry.yarnpkg.com/typescript/-/typescript-3.5.3.tgz#c830f657f93f1ea846819e929092f5fe5983e977"