Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: switch to d2l-test-runner and new vdiffs #82

Merged
merged 2 commits into from
Oct 12, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
8 changes: 4 additions & 4 deletions src/create.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { run as setupElement } from './generators/wc-lit-element/index.js';
import { run as setupLocalization } from './generators/localization/index.js';
import { run as setupRelease } from './generators/release/index.js';
import { run as setupTestUnit } from './generators/test-unit/index.js';
import { run as setupTestVisualDiff } from './generators/test-visual-diff/index.js';
import { run as setupTestVdiff } from './generators/test-vdiff/index.js';

function getClassName(hyphenatedName) {
const hyphenRemoved = hyphenatedName.replace(/-([a-z])/g, (g) => { return g[1].toUpperCase(); });
Expand Down Expand Up @@ -43,8 +43,8 @@ async function getOptions() {
},
{
type: 'select',
name: 'visualDiff',
message: 'Would you like visual-diff tests set up?',
name: 'vdiff',
message: 'Would you like vdiff tests set up?',
choices: [
{ title: 'Yes', value: true },
{ title: 'No', value: false }
Expand Down Expand Up @@ -87,7 +87,7 @@ async function executeGenerator() {
setupDefaultContent(options);
setupElement(options);
setupTestUnit(options);
if (options.visualDiff) setupTestVisualDiff(options);
if (options.vdiff) setupTestVdiff(options);
setupDemo(options);
if (options.localization) setupLocalization(options);
setupRelease(options);
Expand Down
2 changes: 1 addition & 1 deletion src/generators/test-unit/templates/configured/_README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,5 @@ npm run lint:eslint
npm run lint:style

# unit tests
npm run test:headless
npm run test:unit
```
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import '../<%= hyphenatedName %>.js';
import { expect, fixture, html } from '@open-wc/testing';
import { expect, fixture, html } from '@brightspace-ui/testing';
import { runConstructor } from '@brightspace-ui/core/tools/constructor-test-helper.js';
Copy link
Member Author

Choose a reason for hiding this comment

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

Wondering if this runConstructor should also move into @brightspace-ui/testing... seems weird for it to be in core now that we have our own testing library.

Copy link
Contributor

@svanherk svanherk Oct 12, 2023

Choose a reason for hiding this comment

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

Oh yeah it should, we talked about that somewhere else but I guess never made a story for it. Won't be able to remove it from core for a long time but might as well get started!

Copy link
Member Author

Choose a reason for hiding this comment

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

I've added runConstructor to @brightspace-ui/testing and switched this to use it.


describe('<%= className %>', () => {
Expand Down
8 changes: 3 additions & 5 deletions src/generators/test-unit/templates/configured/_package.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
{
"scripts": {
"test": "npm run lint && npm run test:headless",
"test:headless": "web-test-runner --files \"./test/**/*.test.js\" --node-resolve",
"test:headless:watch": "web-test-runner --files \"./test/**/*.test.js\" --node-resolve --watch"
"test": "npm run lint && npm run test:unit",
"test:unit": "d2l-test-runner"
Copy link
Member Author

Choose a reason for hiding this comment

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

I'd like to rename headless to unit since IMO it's a more meaningful name for these types of tests. If others agree, I can make the change in core as well.

Copy link
Contributor

Choose a reason for hiding this comment

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

Sounds good to me, I've never liked headless lol

},
"dependencies": {
"@brightspace-ui/core": "^2"
},
"devDependencies": {
"@open-wc/testing": "^3",
"@web/test-runner": "^0.17"
"@brightspace-ui/testing": "^1"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,5 @@ jobs:
run: npm run lint:eslint
- name: Lint (CSS)
run: npm run lint:style
- name: Unit Tests (cross-browser)
run: npx web-test-runner --files "./test/**/*.test.js" --node-resolve --playwright --browsers chromium firefox webkit
- name: Unit Tests
run: npm run test:unit
24 changes: 24 additions & 0 deletions src/generators/test-vdiff/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { copyFile, copyFilesInDir, getDestinationPath, mergeJSON, mergeText, replaceText } from '../../helper.js';

export function run(templateData) {
mergeJSON(
`${__dirname}/templates/configured/_package.json`,
`${getDestinationPath(templateData.hyphenatedName)}/package.json`
);
mergeText(
`${__dirname}/templates/_README.md`,
`${getDestinationPath(templateData.hyphenatedName)}/README.md`
);
mergeText(
`${__dirname}/templates/_gitignore`,
`${getDestinationPath(templateData.hyphenatedName)}/.gitignore`
);

copyFile(
`${__dirname}/templates/_element.vdiff.js`,
`${getDestinationPath(templateData.hyphenatedName)}/test/${templateData.hyphenatedName}.vdiff.js`
);
replaceText(`${getDestinationPath(templateData.hyphenatedName)}/test/${templateData.hyphenatedName}.vdiff.js`, templateData);

copyFilesInDir(`${__dirname}/templates/static`, getDestinationPath(templateData.hyphenatedName));
}
10 changes: 10 additions & 0 deletions src/generators/test-vdiff/templates/_README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@

This repo uses [@brightspace-ui/testing](https://github.com/BrightspaceUI/testing)'s vdiff command to perform visual regression testing:

```shell
# vdiff
npm run test:vdiff

# re-generate goldens
npm run test:vdiff golden
```
11 changes: 11 additions & 0 deletions src/generators/test-vdiff/templates/_element.vdiff.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import '../<%= hyphenatedName %>.js';
import { expect, fixture, html } from '@brightspace-ui/testing';

describe('<%= tagName %>', () => {

it('default', async() => {
const elem = await fixture(html`<<%= tagName %>></<%= tagName %>>`);
await expect(elem).to.be.golden();
});

});
1 change: 1 addition & 0 deletions src/generators/test-vdiff/templates/_gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.vdiff/
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"scripts": {
"test:vdiff": "d2l-test-runner vdiff"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
name: vdiff
on: pull_request
jobs:
vdiff:
timeout-minutes: 5
runs-on: ubuntu-latest
steps:
- uses: Brightspace/third-party-actions@actions/checkout
- uses: Brightspace/third-party-actions@actions/setup-node
with:
node-version-file: .nvmrc
- name: Install Dependencies
run: npm install
- name: vdiff Tests
uses: BrightspaceUI/actions/vdiff@main
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-session-token: ${{ secrets.AWS_SESSION_TOKEN }}
github-token: ${{ secrets.GITHUB_TOKEN }}
26 changes: 0 additions & 26 deletions src/generators/test-visual-diff/index.js

This file was deleted.

25 changes: 0 additions & 25 deletions src/generators/test-visual-diff/templates/_README.md

This file was deleted.

This file was deleted.

This file was deleted.

2 changes: 0 additions & 2 deletions src/generators/test-visual-diff/templates/_gitignore

This file was deleted.

This file was deleted.