Skip to content

Commit 85c4989

Browse files
authoredOct 11, 2021
Merge pull request #796 from Stuk/ghci
Add Github Actions PR workflow and test with Playwright
2 parents 3f2f0da + 40cc7f4 commit 85c4989

File tree

6 files changed

+1163
-1741
lines changed

6 files changed

+1163
-1741
lines changed
 

‎.github/workflows/pr.yaml

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
name: pull-request
2+
3+
on:
4+
pull_request:
5+
branches: [ master ]
6+
7+
jobs:
8+
test:
9+
runs-on: ubuntu-latest
10+
steps:
11+
- uses: actions/checkout@v2
12+
13+
- uses: actions/setup-node@v2
14+
with:
15+
node-version: 'lts/*'
16+
cache: 'npm'
17+
18+
- name: Cache Node modules
19+
uses: actions/cache@v2
20+
env:
21+
cache-name: cache-node-modules
22+
with:
23+
# npm cache files are stored in `~/.npm` on Linux/macOS
24+
path: ~/.npm
25+
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/package-lock.json') }}
26+
restore-keys: |
27+
${{ runner.os }}-build-${{ env.cache-name }}-
28+
${{ runner.os }}-build-
29+
${{ runner.os }}-
30+
31+
- name: "Install dependencies"
32+
run: |
33+
npm install
34+
sudo npx playwright install-deps
35+
36+
- name: Lint
37+
run: npm run lint
38+
- name: Test Node
39+
run: npm run test-node
40+
- name: Test browsers
41+
run: |
42+
npm run test-browser

‎Gruntfile.js

-59
Original file line numberDiff line numberDiff line change
@@ -2,53 +2,9 @@
22
"use strict";
33

44
module.exports = function(grunt) {
5-
// https://wiki.saucelabs.com/display/DOCS/Platform+Configurator
6-
// A lot of the browsers seem to time out with Saucelab's unit testing
7-
// framework. Here are the browsers that work and get enough coverage for our
8-
// needs.
9-
var browsers = [
10-
{browserName: "chrome"},
11-
{browserName: "firefox", platform: "Linux"},
12-
{browserName: "internet explorer"}
13-
];
14-
15-
var tags = [];
16-
if (process.env.TRAVIS_PULL_REQUEST && process.env.TRAVIS_PULL_REQUEST != "false") {
17-
tags.push("pr" + process.env.TRAVIS_PULL_REQUEST);
18-
} else if (process.env.TRAVIS_BRANCH) {
19-
tags.push(process.env.TRAVIS_BRANCH);
20-
}
21-
225
var version = require("./package.json").version;
236

247
grunt.initConfig({
25-
connect: {
26-
server: {
27-
options: {
28-
base: "",
29-
port: 8080
30-
}
31-
}
32-
},
33-
'saucelabs-qunit': {
34-
all: {
35-
options: {
36-
urls: ["http://127.0.0.1:8080/test/index.html?hidepassed"],
37-
build: process.env.TRAVIS_JOB_ID,
38-
throttled: 4,
39-
"max-duration": 1200, // seconds, IE6 is slow
40-
browsers: browsers,
41-
testname: "qunit tests",
42-
tags: tags,
43-
// Tests have statusCheckAttempts * pollInterval seconds to complete
44-
pollInterval: 2000,
45-
statusCheckAttempts: 240,
46-
"max-duration": 1200,
47-
browsers: browsers,
48-
maxRetries: 2
49-
}
50-
}
51-
},
528
jshint: {
539
// see https://github.com/gruntjs/grunt-contrib-jshint/issues/198
5410
// we can't override the options using the jshintrc path
@@ -102,25 +58,10 @@ module.exports = function(grunt) {
10258
}
10359
});
10460

105-
grunt.loadNpmTasks("grunt-contrib-connect");
106-
grunt.loadNpmTasks("grunt-saucelabs");
10761
grunt.loadNpmTasks('grunt-browserify');
10862
grunt.loadNpmTasks('grunt-contrib-jshint');
10963
grunt.loadNpmTasks('grunt-contrib-uglify');
11064

111-
// A task to cause Grunt to sit and wait, keeping the test server running
112-
grunt.registerTask("wait", function() {
113-
this.async();
114-
});
115-
116-
grunt.registerTask("test-local", ["build", "connect", "wait"]);
117-
grunt.registerTask("test-remote", ["build", "connect", "saucelabs-qunit"]);
118-
119-
if (process.env.SAUCE_USERNAME && process.env.SAUCE_ACCESS_KEY) {
120-
grunt.registerTask("test", ["jshint", "test-remote"]);
121-
} else {
122-
grunt.registerTask("test", ["jshint", "test-local"]);
123-
}
12465
grunt.registerTask("build", ["browserify", "uglify"]);
12566
grunt.registerTask("default", ["jshint", "build"]);
12667
};

‎package-lock.json

+1,044-1,677
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎package.json

+3-3
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"scripts": {
77
"test": "npm run test-node && npm run test-browser",
88
"test-node": "qunit --require ./test/helpers/test-utils.js --require ./test/helpers/node-test-utils.js test/asserts/",
9-
"test-browser": "grunt build && grunt test",
9+
"test-browser": "grunt build && node test/run.js",
1010
"lint": "grunt jshint"
1111
},
1212
"contributors": [
@@ -43,13 +43,13 @@
4343
"grunt": "~0.4.1",
4444
"grunt-browserify": "~5.0.0",
4545
"grunt-cli": "~1.1.0",
46-
"grunt-contrib-connect": "~2.0.0",
4746
"grunt-contrib-jshint": "~1.0.0",
4847
"grunt-contrib-uglify": "~4.0.1",
49-
"grunt-saucelabs": "Stuk/grunt-saucelabs#v10.0.0",
48+
"http-server": "^13.0.2",
5049
"jshint": "~2.9.1",
5150
"jszip-utils": "~0.0.2",
5251
"package-json-versionify": "1.0.2",
52+
"playwright": "^1.15.2",
5353
"qunit": "~2.9.2",
5454
"tmp": "0.0.28"
5555
},

‎test/index.html

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
<head>
44
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
55
<title>JSZip Testing</title>
6-
<link media="screen" href="//code.jquery.com/qunit/qunit-1.23.0.css" type="text/css" rel="stylesheet">
7-
<script type="text/javascript" src="//code.jquery.com/qunit/qunit-1.23.0.js"></script>
6+
<link media="screen" href="../node_modules/qunit/qunit/qunit.css" type="text/css" rel="stylesheet">
7+
<script type="text/javascript" src="../node_modules/qunit/qunit/qunit.js"></script>
88
<script>
99
// no CDN, fallback on the npm version
1010
if(!window.QUnit) {

‎test/run.js

+72
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
const path = require("path");
2+
const playwright = require("playwright");
3+
const createServer = require("http-server").createServer;
4+
5+
/** @typedef {{
6+
name: string,
7+
message: string,
8+
module: string,
9+
result: boolean,
10+
expected: unknown,
11+
actual: unknown,
12+
source: string
13+
}} Failure
14+
*/
15+
16+
/**
17+
* @typedef {{ passed: number, failed: number, total: number, runtime: number, tests: Failure[] }} Results
18+
*/
19+
20+
/**
21+
* @param {string} browserType
22+
* @returns {Promise<[string, Results]>}
23+
*/
24+
async function run(browserType) {
25+
console.log("Starting", browserType);
26+
const browser = await playwright[browserType].launch();
27+
const context = await browser.newContext();
28+
const page = await context.newPage();
29+
30+
await page.goto(`http://127.0.0.1:8080/test/index.html?hidepassed`);
31+
32+
let result;
33+
do {
34+
result = await page.evaluate(() => {
35+
return window.global_test_results;
36+
});
37+
} while (!result)
38+
39+
console.log("Closing", browserType);
40+
await browser.close();
41+
42+
return [browserType, result];
43+
}
44+
45+
async function main() {
46+
const browsersTypes = ["chromium", "firefox", "webkit"];
47+
48+
const server = createServer({root: path.join(__dirname, "..")});
49+
await new Promise(resolve => server.listen(8080, "127.0.0.1", resolve));
50+
console.log("Server started");
51+
52+
try {
53+
const results = await Promise.all(browsersTypes.map(run));
54+
55+
let failures = false;
56+
for (const result of results) {
57+
console.log(...result);
58+
failures = failures || result[1].failed > 0;
59+
}
60+
61+
if (failures) {
62+
console.log("Tests failed");
63+
process.exit(1);
64+
} else {
65+
console.log("Tests passed!");
66+
}
67+
} finally {
68+
server.close();
69+
}
70+
}
71+
72+
main();

0 commit comments

Comments
 (0)
Please sign in to comment.