Skip to content

Commit 0c4fde9

Browse files
author
Westbrook Johnson
committed
feat(testing-library__dom): monkey patched testing-library__dom mirror
1 parent 88c8d5c commit 0c4fde9

File tree

11 files changed

+682
-30
lines changed

11 files changed

+682
-30
lines changed

.circleci/config.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ version: 2.1
22
executors:
33
node:
44
docker:
5-
- image: circleci/node:10.16.0-browsers
5+
- image: circleci/node:10.18.1-browsers
66
environment:
77
NPM_CONFIG_PREFIX: ~/.npm-global
88
CHROME_BIN: /usr/bin/google-chrome

karma.conf.js

+1
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ module.exports = (config) => {
2828
babelConfig: {
2929
plugins: ['transform-node-env-inline'],
3030
},
31+
coverageExclude: ['projects/**/*'],
3132
},
3233
browsers: ['FirefoxHeadlessCustom'],
3334
customLaunchers: {

package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
"type": "module",
2828
"browser": "lib/index.js",
2929
"engines": {
30-
"node": ">=10.15.0",
30+
"node": ">=10.18.0",
3131
"yarn": ">=1.16.0"
3232
},
3333
"scripts": {
@@ -62,7 +62,7 @@
6262
"prelerna-publish": "yarn get-ready && yarn custom-element-json",
6363
"lerna-publish": "lerna publish --message 'chore: release new versions'",
6464
"test": "yarn build && yarn test:ci",
65-
"test:build": "tsc --build test/tsconfig-test.json",
65+
"test:build": "tsc --build test/tsconfig-test.json && lerna exec --scope testing-library__dom -- yarn build",
6666
"test:ci": "yarn test:build && karma start --coverage",
6767
"test:start": "karma start",
6868
"test:watch": "run-p watch 'test:build -w' 'test:start --auto-watch=true --single-run=false'",

packages/actionbar/test/actionbar.test.ts

+10-3
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import { Actionbar } from '../';
1515
import { fixture, elementUpdated, html, expect } from '@open-wc/testing';
1616
import { waitForPredicate } from '../../../test/testing-helpers';
1717
import '../../shared/lib/focus-visible.js';
18+
import { getByLabelText } from 'testing-library__dom';
1819

1920
describe('Actionbar', () => {
2021
it('loads', async () => {
@@ -23,7 +24,7 @@ describe('Actionbar', () => {
2324
<sp-actionbar open>
2425
<sp-checkbox indeterminate>228 Selected</sp-checkbox>
2526
<div class="spectrum-ButtonGroup">
26-
<sp-action-button quiet>
27+
<sp-action-button quiet label="Edit">
2728
<svg
2829
slot="icon"
2930
id="spectrum-icon-18-Edit"
@@ -54,8 +55,14 @@ describe('Actionbar', () => {
5455
await elementUpdated(el);
5556

5657
expect(el).to.not.be.undefined;
57-
expect(el).lightDom.to.equalSnapshot();
58-
expect(el).shadowDom.to.equalSnapshot();
58+
// expect(el).lightDom.to.equalSnapshot();
59+
// expect(el).shadowDom.to.equalSnapshot();
60+
61+
// const renderRoot = el.shadowRoot
62+
// ? (el.shadowRoot as unknown) as HTMLElement
63+
// : el as HTMLElement;
64+
const input = getByLabelText(el, 'Edit');
65+
expect(input).to.not.be.undefined;
5966
});
6067

6168
it('accepts variants', async () => {

packages/sidenav/test/sidenav-item.test.ts

+17-10
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ governing permissions and limitations under the License.
1313
import '../';
1414
import { SideNavItem } from '../';
1515
import { fixture, elementUpdated, html, expect } from '@open-wc/testing';
16+
import { getByText, queryByText } from 'testing-library__dom';
1617

1718
describe('Sidenav Item', () => {
1819
it('can exist disabled and with no parent', async () => {
@@ -68,24 +69,30 @@ describe('Sidenav Item', () => {
6869

6970
await elementUpdated(el);
7071

71-
expect(el.shadowRoot).to.exist;
72-
if (!el.shadowRoot) return;
73-
74-
let slot = el.shadowRoot.querySelector('slot');
75-
expect(slot).not.to.exist;
72+
let section1 = queryByText(el, 'Section 1');
73+
let section2 = queryByText(el, 'Section 2');
7674

7775
expect(el.expanded).to.be.false;
76+
expect(section1, 'section 1: closed initial').to.be.null;
77+
expect(section2, 'section 2: closed initial').to.be.null;
7878

7979
el.click();
80-
8180
await elementUpdated(el);
8281

8382
expect(el.expanded).to.be.true;
83+
section1 = getByText(el, 'Section 1');
84+
section2 = getByText(el, 'Section 2');
85+
expect(section1, 'section 1: opened').to.not.be.null;
86+
expect(section2, 'section 2: opened').to.not.be.null;
87+
88+
el.click();
89+
await elementUpdated(el);
8490

85-
slot = el.shadowRoot.querySelector('slot');
86-
expect(slot).to.exist;
87-
if (!slot) return;
91+
section1 = queryByText(el, 'Section 1');
92+
section2 = queryByText(el, 'Section 2');
8893

89-
expect(slot.assignedElements().length).to.equal(2);
94+
expect(el.expanded).to.be.false;
95+
expect(section1, 'section 1: closed').to.be.null;
96+
expect(section2, 'section 2: closed').to.be.null;
9097
});
9198
});
+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
dom.js
+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
// TypeScript Version: 2.8
2+
export * from '@testing-library/dom';
+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
HTMLElement.prototype.querySelectorAllWithShadowDOM = function(query) {
2+
const isNotCustomElementParent = this.tagName.search('-') === -1;
3+
const children = [...(this.children || [])].filter(
4+
(child) => isNotCustomElementParent || !!child.assignedSlot
5+
);
6+
let results = children.filter((el) => el.matches(query));
7+
if (this.shadowRoot) {
8+
results = results.concat([
9+
...(this.shadowRoot.querySelectorAllWithShadowDOM(query) || []),
10+
]);
11+
}
12+
children.map((child) => {
13+
if (child.querySelectorAllWithShadowDOM) {
14+
results = results.concat([
15+
...(child.querySelectorAllWithShadowDOM(query) || []),
16+
]);
17+
}
18+
});
19+
return results;
20+
};
21+
22+
ShadowRoot.prototype.querySelectorAllWithShadowDOM = function(query) {
23+
const children = [...(this.children || [])];
24+
let results = children.filter((el) => el.matches(query));
25+
children.map((child) => {
26+
results = results.concat([
27+
...(child.querySelectorAllWithShadowDOM(query) || []),
28+
]);
29+
});
30+
return results;
31+
};
32+
33+
export * from './dom.js';
+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
{
2+
"name": "testing-library__dom",
3+
"version": "7.0.0-beta.4",
4+
"description": "mirror of @testing-library/dom, bundled and exposed as ES module",
5+
"author": "",
6+
"main": "index.js",
7+
"publishConfig": {
8+
"access": "public"
9+
},
10+
"repository": {
11+
"type": "git",
12+
"url": "git://github.com/bundled-es-modules/testing-library-dom.git"
13+
},
14+
"license": "Apache-2.0",
15+
"devDependencies": {
16+
"@rollup/plugin-alias": "^2.2.0",
17+
"@rollup/plugin-replace": "^2.2.1",
18+
"@testing-library/dom": "7.0.0-beta.4",
19+
"babel-core": "^6.26.3",
20+
"core-js": "^2.5.7",
21+
"rollup": "^1.0.0",
22+
"rollup-plugin-commonjs": "^9.0.0",
23+
"rollup-plugin-copy": "^3.0.0",
24+
"rollup-plugin-ignore": "^1.0.5",
25+
"rollup-plugin-node-builtins": "^2.1.2",
26+
"rollup-plugin-node-globals": "^1.4.0",
27+
"rollup-plugin-node-resolve": "^4.0.0",
28+
"rollup-plugin-replace": "^2.1.0",
29+
"semver": ">=4.3.2"
30+
},
31+
"scripts": {
32+
"build": "rollup -c ./rollup.config.js"
33+
}
34+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import resolve from 'rollup-plugin-node-resolve';
2+
import commonjs from 'rollup-plugin-commonjs';
3+
import replace from '@rollup/plugin-replace';
4+
5+
export default [
6+
{
7+
input: require.resolve(
8+
'@testing-library/dom/dist/@testing-library/dom.esm.js'
9+
),
10+
output: {
11+
file: './dom.js',
12+
format: 'es',
13+
},
14+
plugins: [
15+
resolve({
16+
browser: true,
17+
preferBuiltins: false,
18+
}),
19+
commonjs(),
20+
replace({
21+
querySelectorAll: 'querySelectorAllWithShadowDOM',
22+
}),
23+
],
24+
},
25+
];

0 commit comments

Comments
 (0)