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

chore(.travis): check spec for errors/warnings #739

Merged
merged 8 commits into from
Nov 13, 2018
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: 4 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
language: node_js
node_js:
- lts/*

branches:
only:
Expand All @@ -11,7 +13,8 @@ env:
- secure: "vuLLjmy5cSalvR4ut2Q28YJgVUoSmLQYlhNRyF7zVskO5VFX7RHpfWokrk1SXEQ5hI8bpWOYJOVrcYr05BP0cFvsESlDejaur4rw/gT2nfMkuyWbVhbxH9mFYKeVFWpoC+iezrao9VjMRYySjEJAM4B9mXflN3MQ6ddRaQlBMaI="

script:
- echo "ok"
- npm install respec serve
- node ./tools/validate.js

after_success:
- CC="mcaceres@mozilla.com,mgiuca@google.com"
Expand Down
4 changes: 0 additions & 4 deletions PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,6 @@ This change (choose one):
changes normative sections without changing behavior)
* [ ] Is a "chore" (metadata, formatting, fixing warnings, etc).

The following tasks have been completed:

* [ ] Confirmed there are no new ReSpec errors/warnings.

Implementation commitment (delete if not making normative changes):

* [ ] Safari (link to issue)
Expand Down
58 changes: 58 additions & 0 deletions tools/validate.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
#!/usr/bin/env node
/*eslint-env node*/
"use strict";
const { exec } = require("child_process");
const handler = require("serve-handler");
const http = require("http");

/**
*
* @param {string} cmd A string representing a shell command.
*/
class ShellCommand {
constructor(cmd) {
this._cmd = cmd;
}
get cmd() {
return this._cmd;
}
run() {
return new Promise((resolve, reject) => {
const childProcess = exec(this.cmd, (err, data) => {
if (err) {
return reject(err);
}
resolve(data);
});
childProcess.stdout.pipe(process.stdout);
childProcess.stderr.pipe(process.stderr);
});
}
}

/**
* Spins up a local HTTP server and checks the spec.
* If there are any errors or warnings, the app exits with 1.
*/
async function validate() {
const server = http.createServer((request, response) =>
handler(request, response)
);
server.listen(5000, () => {});
const url = `http://localhost:5000/index.html?githubToken=${
// This "AUTHENTICATE" is a GitHub token https://github.com/settings/tokens
// It needs to be set set on TravisCI itself, via the in the settings
// or using Travis' encrypt.
process.env.AUTHENTICATE
}`;
// -e is stop on errors, -w is stop on warnings
const cmd = `npx respec2html -e -w --timeout 30 --src ${url} --out /dev/null`;
try {
await new ShellCommand(cmd).run();
} catch (err) {
process.exit(1);
}
process.exit(0);
}

validate();