Skip to content

Commit 501b736

Browse files
committed
spike(ava): Switch from mocha/chai
refact(visreg): Share one set of tests for both browsers fix(visreg): Remove debugging 'exit(0)' statement fix(visreg): Allow for informational messages again fix(visreg): Use geckodriver refact(visreg): Move tests out of util chore(jest): Don't load browser context for visreg test(jest): Outline 'functional' tests refact(tests): Split each test type into dedicated directory docs(util): Better document 'page object' and its future style(testing): Avoid scientific notation for big numbers fix(script): Update reference away from deleted script fix(tsconfig): Include custom type hints fix(visreg): Honor the actual screenshot directory fix(visreg): Wrong path to visreg config file fix(visreg): Refer to new npm run script fix(jest): Don't spin up jsdom environment fix(jest): Optimize for selenium fix(visreg): Avoid large png files chore(yarn): Switch to ava test(ava): Convert to ava style(visreg): Remove missing comment style(visreg): Remove unused template literals
1 parent 36d1b96 commit 501b736

File tree

17 files changed

+2712
-374
lines changed

17 files changed

+2712
-374
lines changed

test/.gitignore

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
.github-token
2-
bin/*.js
32
bin/visreg.config.ts
43
built/
5-
index.js
6-
screenshots
4+
!built/functional/*.js.snap
5+
!built/functional/*.js.md
6+
screenshots

test/bin/util.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ export function createBaseline(
104104
"git commit --allow-empty -m \"Baseline.\"",
105105
"cd -"
106106
].join('; '));
107-
cmd(`git checkout ${targetBranch}; npm test`);
107+
cmd(`git checkout ${targetBranch}; npm run test:visreg`);
108108

109109
const commit = commitScreenshots(token, screenshotsDirectory, "before").toString();
110110
const baseCommitMatch = commit.match(hasCommitRegex);
@@ -118,7 +118,7 @@ export function createBaseline(
118118
}
119119

120120
export function createDiff(token: string, currentBranch: string, screenshotsDirectory: string) {
121-
cmd(`git checkout ${currentBranch}; npm test`);
121+
cmd(`git checkout ${currentBranch}; npm run test:visreg`);
122122
const afterCommitData = commitScreenshots(token, screenshotsDirectory, "after").toString();
123123
const afterCommitMatch = afterCommitData.match(hasCommitRegex);
124124
const afterCommit = afterCommitMatch && afterCommitMatch[1];
@@ -251,7 +251,7 @@ export function resetRepository(screenshotsDirectory: string) {
251251
export function cloneRepo(token: string, screenshotsDirectory: string, repoUrl: url.Url) {
252252
let cloneUrl = `https://${token}@${repoUrl.host}${repoUrl.path}.git`;
253253
console.log(`Cloning a screenshots project into "${path.resolve(screenshotsDirectory)}"`);
254-
safeExecSync(token, `git clone ${cloneUrl} screenshots/ > /dev/null`)
254+
safeExecSync(token, `git clone ${cloneUrl} ${screenshotsDirectory}/ > /dev/null`)
255255

256256
console.log(`Cloned a screenshots project into "${path.resolve(screenshotsDirectory)}"`);
257257
};

test/bin/visreg.d.ts

Whitespace-only changes.

test/bin/visreg.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import * as opn from "opn"
77
import * as util from "./util";
88

99
import {config, IConfig} from "./visreg.config";
10-
const screenshotsDirectory = "screenshots";
10+
const screenshotsDirectory = "visreg/screenshots";
1111

1212
async function visreg(
1313
currentBranch: string,
@@ -29,8 +29,6 @@ async function visreg(
2929
const token = await util.validateToken(await util.getGithubToken());
3030
const repoUrl = url.parse(`https://${config.githubHostname}/${config.githubName}/${config.repo}`);
3131

32-
process.exit(0);
33-
3432
util.resetRepository(screenshotsDirectory);
3533
if (!util.repositoryExists(token, repoUrl)) {
3634
console.log(`Creating a new screenshots repository at ${repoUrl.href}`);
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# Snapshot report for `built/functional/hx-reveal.js`
2+
3+
The actual snapshot is saved in `hx-reveal.js.snap`.
4+
5+
Generated by [AVA](https://ava.li).
6+
7+
## should not be open
8+
9+
> Snapshot 1
10+
11+
`<hx-reveal>␊
12+
<span slot="summary">Click me to show content</span>␊
13+
<p>You can't see me.</p>␊
14+
</hx-reveal>`
15+
16+
## should open
17+
18+
> Snapshot 1
19+
20+
`<hx-reveal open="">␊
21+
<span slot="summary">Click me to show content</span>␊
22+
<p>You can't see me.</p>␊
23+
</hx-reveal>`
225 Bytes
Binary file not shown.

test/util.ts renamed to test/common/util.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
* Helper functions for the tests in `index.ts`.
33
*/
44
import {By, ISize, ThenableWebDriver, WebDriver, WebElementPromise} from "selenium-webdriver";
5+
56
export async function setViewportSize (
67
driver: ThenableWebDriver,
78
size: ISize,
@@ -30,7 +31,12 @@ export function $x(
3031
return driver.findElement(By.xpath(xpath));
3132
}
3233

33-
// "page object"
34-
export var $ = {
34+
/* A "starter page object" until there's a greater need for something more robust.
35+
* For now this only contains common CSS selectors used throughout tests in the
36+
* visreg/functional directories, but may also contain functions in the future.
37+
*
38+
* Once that happens, pull this out of `util.ts` and move it someplace more page-object-y.
39+
*/
40+
export var selectors = {
3541
nav: ".hxApp__nav",
3642
}

test/functional/hx-reveal.ts

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import {$, snap, Snappit, IConfig} from "snappit-visual-regression";
2+
import {WebDriver, WebElementPromise} from "selenium-webdriver";
3+
4+
import {test, TestContext} from "ava";
5+
6+
const baseUrl = "http://localhost:3000/helix-ui";
7+
const snapshot = async (t: TestContext, element: WebElementPromise) => {
8+
t.snapshot(await element.getAttribute("outerHTML"));
9+
};
10+
11+
let snappit: Snappit;
12+
let driver: WebDriver;
13+
let reveal: WebElementPromise;
14+
15+
test.before(async () => {
16+
const config: IConfig = {
17+
browser: "chrome",
18+
serverUrl: "http://localhost:4444/wd/hub",
19+
};
20+
21+
snappit = new Snappit(config);
22+
driver = await snappit.start();
23+
await driver.get(`${baseUrl}/components/reveal`);
24+
reveal = $(".demo hx-reveal");
25+
});
26+
27+
test("should not be open", async t => {
28+
t.is(await reveal.getAttribute("open"), null);
29+
await snapshot(t, reveal);
30+
});
31+
32+
test("should open", async t => {
33+
await reveal.click();
34+
t.is(await reveal.getAttribute("open"), "true");
35+
await snapshot(t, reveal);
36+
});
37+
38+
test.after.always(async () => {
39+
await snappit.stop();
40+
});

test/index.d.ts

Whitespace-only changes.

test/index.ts

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

0 commit comments

Comments
 (0)