Skip to content

Commit 5ae7525

Browse files
authored
fix: get web-component test for example-button working (#357)
* fix: fix web-component tests * chore: install playwright on ci-check * chore: fix ci-check * chore: fix ci-check * chore: fix ci-check * chore: update generate script * chore: fix ci-tests * chore: remove playwright temporarily
1 parent e606cc1 commit 5ae7525

File tree

14 files changed

+81
-169
lines changed

14 files changed

+81
-169
lines changed

.github/workflows/ci.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,3 +90,6 @@ jobs:
9090
- name: run React tests
9191
working-directory: 'packages/react'
9292
run: yarn test
93+
- name: run Web Component tests
94+
working-directory: 'packages/web-components'
95+
run: yarn test

docs/developing.md

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
- [Building a Web Component](#building-a-web-component)
1414
- [Document maintainers](#document-maintainers)
1515
- [Submitting a Pull Request](#submitting-a-pull-request)
16+
- [Publishing to NPM](#publishing-to-npm)
1617

1718
<!-- END doctoc generated TOC please keep comment here to allow auto update -->
1819
<!-- prettier-ignore-end -->
@@ -137,10 +138,7 @@ might want to run:
137138
- The component folder (`packages/react/src/components/TestComponent`).
138139
- The package name for the component will begin with `@carbon-labs/react-*`.
139140

140-
2. Rename the `package-edit.json` files to `package.json` in both the examples
141-
folder and component folder.
142-
143-
3. From the root of the project, run the following to add your component to the
141+
2. From the root of the project, run the following to add your component to the
144142
yarn workspace.
145143
```bash
146144
yarn && yarn build
@@ -170,10 +168,7 @@ might want to run:
170168
(`packages/web-components/src/components/test-component`).
171169
- The package name for the component will begin with `@carbon-labs/wc-*`.
172170

173-
2. Rename the `package-edit.json` files to `package.json` in both the examples
174-
folder and component folder.
175-
176-
3. From the root of the project, run the following to add your component to the
171+
2. From the root of the project, run the following to add your component to the
177172
yarn workspace.
178173
```bash
179174
yarn && yarn build
@@ -248,3 +243,12 @@ file (within `<component-name>/__stories__/<component-name>.mdx`)
248243

249244
Once all revisions to your pull request are complete, a maintainer will
250245
squash and merge your commits for you.
246+
247+
## Publishing to NPM
248+
249+
The
250+
[canary publish to NPM](https://github.com/carbon-design-system/carbon-labs/actions/workflows/release-canary.yml)
251+
occurs every time a PR is merged into `main`. This canary version of your
252+
package can be used in your applications.
253+
[Full minor releases](https://github.com/carbon-design-system/carbon-labs/actions/workflows/release.yml)
254+
occur when needed and are triggered manually.

package.json

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,15 +33,10 @@
3333
"devDependencies": {
3434
"@commitlint/cli": "^19.0.0",
3535
"@commitlint/config-conventional": "^19.0.0",
36-
"@open-wc/testing": "^4.0.0",
37-
"@playwright/test": "^1.39.0",
3836
"@types/fs-extra": "^11.0.4",
3937
"@types/mocha": "^10.0.3",
4038
"@types/react": "^18.2.36",
4139
"@types/sinon": "^17.0.0",
42-
"@web/test-runner": "^0.19.0",
43-
"@web/test-runner-commands": "^0.9.0",
44-
"@web/test-runner-playwright": "^0.11.0",
4540
"babel-preset-carbon": "^0.0.14",
4641
"chalk": "^5.4.1",
4742
"change-case": "^5.4.4",

packages/react/tasks/generate/index.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,13 @@ sync(resolve(templatesPath, '**/*')).forEach((template) => {
5858
}
5959

6060
let relativePath = relative(templatesPath, template);
61+
62+
// needed to name the template package.json file to 'package-edit.json' otherwise
63+
// yarn tries to register the template as a package, so swapping back to package.json here
64+
if (relativePath.includes('package-edit.json')) {
65+
relativePath = relativePath.replace('package-edit.json', 'package.json');
66+
}
67+
6168
const compiledPath = compile(relativePath);
6269
let path;
6370

packages/web-components/package.json

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@
2424
"generate": "node tasks/generate",
2525
"storybook": "storybook dev -p 6006",
2626
"storybook:build": "npx storybook build",
27-
"test": "yarn build && web-test-runner \"packages/**/*.test.ts\" --node-resolve --playwright --browsers chromium firefox webkit",
28-
"test:updateSnapshot": "yarn build && web-test-runner \"packages/**/*.test.ts\" --node-resolve --update-snapshots"
27+
"test": "yarn build && web-test-runner \"src/components/**/*.test.js\" --node-resolve",
28+
"test:updateSnapshot": "yarn build && web-test-runner \"src/components/**/*.test.js\" --node-resolve --update-snapshots"
2929
},
3030
"dependencies": {
3131
"@carbon/styles": "^1.70.0",
@@ -42,6 +42,7 @@
4242
"@custom-elements-manifest/analyzer": "^0.10.0",
4343
"@lit/react": "^1.0.1",
4444
"@open-wc/testing": "^4.0.0",
45+
"@playwright/test": "^1.39.0",
4546
"@rollup/plugin-alias": "^5.1.0",
4647
"@rollup/plugin-commonjs": "^28.0.0",
4748
"@rollup/plugin-json": "^6.1.0",
@@ -57,6 +58,9 @@
5758
"@storybook/theming": "^8.4.7",
5859
"@storybook/web-components": "^8.4.7",
5960
"@storybook/web-components-vite": "^8.4.7",
61+
"@web/test-runner": "^0.19.0",
62+
"@web/test-runner-commands": "^0.9.0",
63+
"@web/test-runner-playwright": "^0.11.0",
6064
"async-done": "^2.0.0",
6165
"autoprefixer": "^10.4.20",
6266
"browserslist-config-carbon": "^11.2.0",

packages/web-components/src/components/chat/__tests__/__snapshots__/test-input.test.snap.js

Lines changed: 0 additions & 56 deletions
This file was deleted.

packages/web-components/src/components/chat/__tests__/test-input.test.ts

Lines changed: 0 additions & 72 deletions
This file was deleted.
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
/* @web/test-runner snapshot v1 */
2+
export const snapshots = {};
3+
4+
snapshots["clabs-example-button should render with cds-button minimum attributes"] =
5+
`<clabs-example-button
6+
has-main-content=""
7+
kind="primary"
8+
size="lg"
9+
tooltip-alignment=""
10+
tooltip-position="top"
11+
type="button"
12+
>
13+
button
14+
</clabs-example-button>
15+
`;
16+
/* end snapshot clabs-example-button should render with cds-button minimum attributes */
17+

packages/web-components/src/components/example-button/__tests__/__snapshots__/extended-button.test.snap.js

Lines changed: 0 additions & 17 deletions
This file was deleted.

packages/web-components/src/components/example-button/__tests__/example-button.test.ts renamed to packages/web-components/src/components/example-button/__tests__/example-button.test.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,11 @@
88
*/
99

1010
import { html, fixture, expect } from '@open-wc/testing';
11-
import '@carbon-labs/ai-example-button/es/components/example-button/example-button.js';
12-
import CLABSExampleButton from '../components/example-button/example-button.js';
11+
import '@carbon-labs/wc-example-button/es/index.js';
1312

1413
describe('clabs-example-button', function () {
1514
it('should render with cds-button minimum attributes', async () => {
16-
const el = await fixture<CLABSExampleButton>(
15+
const el = await fixture(
1716
html`<clabs-example-button> button </clabs-example-button>`
1817
);
1918

0 commit comments

Comments
 (0)