Skip to content
This repository has been archived by the owner on Sep 26, 2023. It is now read-only.

Port bash scripts to JS #548

Merged
merged 10 commits into from
Oct 5, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 2 additions & 3 deletions .github/workflows/pull_request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,8 @@ jobs:
runs-on: ubuntu-latest
- name: macOS
runs-on: macos-latest
# TODO: https://github.com/foolip/mdn-bcd-collector/issues/546
#- name: Windows
# runs-on: windows-latest
- name: Windows
runs-on: windows-latest
name: Test (${{ matrix.name }})
runs-on: ${{ matrix.runs-on }}
steps:
Expand Down
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,16 @@
"node": ">=12"
},
"scripts": {
"prepare": "if [ -d node_modules/puppeteer ]; then cd node_modules/puppeteer && PUPPETEER_PRODUCT=firefox node install.js; fi",
"lint": "eslint . && prettier -c '**/*.json' '**/*.md' '**/*.yaml' --color && ejslint views/*",
"lint-fix": "eslint --fix . && prettier --write '**/*.json' '**/*.md' '**/*.yaml'",
"prepare": "node scripts.js prepare",
"lint": "eslint . && prettier -c \"**/*.json\" \"**/*.md\" \"**/*.yaml\" --color && ejslint views/*",
"lint-fix": "eslint --fix . && prettier --write \"**/*.json\" \"**/*.md\" \"**/*.yaml\"",
"clean": "rm -rf .nyc_output coverage generated tests.json",
"build": "node build.js",
"gcp-build": "npm run build",
"deploy": "gcloud app deploy",
"start": "node app.js",
"start-dev": "nodemon --exec 'npm run build && npm start'",
"unittest": "NODE_ENV=test nyc mocha --recursive unittest",
"unittest": "node scripts.js unittest",
"coverage": "nyc report -r lcov && open-cli coverage/lcov-report/index.html",
"test": "npm run lint && npm run unittest",
"selenium": "node selenium.js",
Expand Down
37 changes: 37 additions & 0 deletions scripts.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// Copyright 2020 Mozilla Corporation
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

const childProcess = require('child_process');
saschanaz marked this conversation as resolved.
Show resolved Hide resolved

const exec = (cmd, env) => {
env = {...process.env, ...env};
console.log(`> ${cmd}`);
return childProcess.execSync(cmd, {env, stdio: 'inherit'});
};

const prepare = () => {
try {
process.chdir('node_modules/puppeteer');
} catch {
return;
}
exec('node install.js', {PUPPETEER_PRODUCT: 'firefox'});
};

const command = process.argv[2];
if (command === 'prepare') {
prepare();
} else if (command === 'unittest') {
exec('nyc mocha --recursive unittest', {NODE_ENV: 'test'});
}
10 changes: 9 additions & 1 deletion unittest/puppeteer/harness.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,15 @@ describe('harness.js', () => {
after(() => server.close());

for (const product of products) {
it(product, async () => {
it(product, async function() {
if (product === 'firefox' && process.platform === 'win32' &&
require('../../package.json').devDependencies.puppeteer === '5.3.1') {
// Browser.close() Firefox support is broken on Windows and causes hang
// https://github.com/puppeteer/puppeteer/issues/5673
/* eslint-disable no-invalid-this */
this.skip();
return;
}
const browser = await puppeteer.launch({product});
after(() => browser.close());

Expand Down