Skip to content
This repository has been archived by the owner on Jun 7, 2024. It is now read-only.

Commit

Permalink
feat(w3c): make a jQuery-less profile (w3c) (speced#2249)
Browse files Browse the repository at this point in the history
  • Loading branch information
marcoscaceres committed Apr 12, 2019
1 parent 73612c0 commit 3ed6dc6
Show file tree
Hide file tree
Showing 21 changed files with 200 additions and 61 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,6 @@ bevy.json
js/
!js/profile-w3c-common.js
!js/profile-geonovum.js
!js/profile-w3c.js
!js/shortcut.js
.vscode/
13 changes: 6 additions & 7 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,24 @@ language: node_js
dist: xenial
node_js:
- lts/*

install:
- npm install
- npm run build
- npm run build:respec-w3c-common
- npm run build:geonovum

cache:
directories:
- node_modules # NPM packages

install:
- npm install

jobs:
include:
- stage: Run eslint
script:
- npm run lint
- stage: Run headless
script:
- npm run build:w3c
- npm run test:headless
- stage: Run Karma unit tests
script:
- npm run build:w3c
- npm run build:geonovum
- travis_retry karma start --single-run --reporters mocha karma.conf.js
17 changes: 17 additions & 0 deletions builds/respec-geonovum.js

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions builds/respec-geonovum.js.map

Large diffs are not rendered by default.

17 changes: 17 additions & 0 deletions builds/respec-w3c.js

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions builds/respec-w3c.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion examples/basic.built.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<head>
<meta charset='utf-8'>
<title>Replace me with a real title</title>
<script src="../builds/respec-w3c-common.js" class='remove'></script>
<script src="../builds/respec-w3c.js" class='remove'></script>
<script class='remove'>
var respecConfig = {
specStatus: "ED",
Expand Down
2 changes: 1 addition & 1 deletion examples/basic.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<title>
Replace me with a real title
</title>
<script src='../js/deps/require.js' data-main='../js/profile-w3c-common'
<script src='../js/deps/require.js' data-main='../js/profile-w3c'
async class='remove'></script>
<script class='remove'>
var respecConfig = {
Expand Down
2 changes: 1 addition & 1 deletion examples/starter.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<html>
<head>
<meta charset='utf-8'>
<script src='//www.w3.org/Tools/respec/respec-w3c-common' async class='remove'></script>
<script src='https://www.w3.org/Tools/respec/respec-w3c' async class='remove'></script>
<script class='remove'>
var respecConfig = {
specStatus: "unofficial",
Expand Down
2 changes: 1 addition & 1 deletion js/profile-w3c-common.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ window.addEventListener("error", ev => {
// this is only set in a build, not at all in the dev environment
require.config({
paths: {
clipboard: "deps/clipboard",
hyperhtml: "deps/hyperhtml",
idb: "deps/idb",
jquery: "deps/jquery",
Expand All @@ -30,6 +29,7 @@ define([
// order is significant
"./core/base-runner",
"./core/ui",
"./core/jquery-enhanced",
"./core/reindent",
"./core/location-hash",
"./core/l10n",
Expand Down
98 changes: 98 additions & 0 deletions js/profile-w3c.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
"use strict";
// In case everything else fails, we want the error
window.addEventListener("error", ev => {
console.error(ev.error, ev.message, ev);
});

// this is only set in a build, not at all in the dev environment
require.config({
paths: {
hyperhtml: "deps/hyperhtml",
idb: "deps/idb",
marked: "deps/marked",
pluralize: "deps/pluralize",
text: "deps/text",
webidl2: "deps/webidl2",
},
shim: {
shortcut: {
exports: "shortcut",
},
idb: {
exports: "idb",
},
},
});

define([
// order is significant
"./core/base-runner",
"./core/ui",
"./core/reindent",
"./core/location-hash",
"./core/l10n",
"./w3c/defaults",
"./core/style",
"./w3c/style",
"./w3c/l10n",
"./core/github",
"./core/data-include",
"./core/markdown",
"./w3c/headers",
"./w3c/abstract",
"./core/data-transform",
"./core/data-abbr",
"./core/inlines",
"./w3c/conformance",
"./core/dfn",
"./core/pluralize",
"./core/examples",
"./core/issues-notes",
"./core/requirements",
"./core/best-practices",
"./core/figures",
"./core/webidl",
"./core/data-cite",
"./core/biblio",
"./core/webidl-index",
"./core/link-to-dfn",
"./core/render-biblio",
"./core/contrib",
"./core/fix-headers",
"./core/structure",
"./core/informative",
"./core/id-headers",
"./core/caniuse",
"./ui/save-html",
"./ui/search-specref",
"./ui/dfn-list",
"./ui/about-respec",
"./core/seo",
"./w3c/seo",
"./core/highlight",
"./core/webidl-clipboard",
"./core/data-tests",
"./core/list-sorter",
"./core/highlight-vars",
"./core/algorithms",
/* Linter must be the last thing to run */
"./core/linter",
], (runner, { ui }, ...plugins) => {
ui.show();
const loadPromise = new Promise(r => {
if (document.readyState !== "loading") {
r();
return;
}
document.addEventListener("DOMContentLoaded", r)
});
loadPromise.then(async () => {
try {
await runner.runAll(plugins);
} catch (err) {
console.error(err);
} finally {
ui.enable();
}
});
});
8 changes: 8 additions & 0 deletions karma.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,14 @@ module.exports = function(config) {

// See "detectBrowsers"
// browsers: ["Chrome", "Safari", "Firefox"],
customLaunchers: {
FirefoxPref: {
base: "Firefox",
prefs: {
"javascript.options.dynamicImport": true,
},
},
},

// Continuous Integration mode
// if true, Karma captures browsers, runs the tests and exits
Expand Down
31 changes: 17 additions & 14 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
"karma-safaritechpreview-launcher": "2.0.2",
"karma-verbose-summary-reporter": "0.0.1",
"marked": "^0.6.2",
"mocha": "^6.1.2",
"mocha": "^6.1.3",
"moment": "^2.24.0",
"pluralize": "^7.0.0",
"prettier": "^1.16.4",
Expand All @@ -73,10 +73,10 @@
"scripts": {
"babel:build": "babel src -d js --source-maps -q",
"babel:watch": "babel src -d js --watch --source-maps",
"build:respec-w3c-common": "node ./tools/builder.js --profile=w3c-common",
"build:w3c": "node ./tools/builder.js --profile=w3c",
"build:geonovum": "node ./tools/builder.js --profile=geonovum",
"build:components": "npm run copydeps && npm run babel:build",
"build:respec-w3c-common": "node ./tools/builder.js --profile=w3c-common",
"build:w3c-with-jquery": "node ./tools/builder.js --profile=w3c-common",
"build": "snyk protect && npm run build:components",
"copydeps": "node ./tools/copydeps.js",
"karma": "karma start --single-run",
Expand All @@ -87,7 +87,7 @@
"snyk-protect": "snyk protect",
"snyk": "snyk",
"start": "npm run build:components && serve",
"test:build": "mocha ./tests/test-build.js",
"test:build": "mocha --timeout 60000 ./tests/test-build.js",
"test:headless": "node ./tests/headless.js",
"test:karma": "npm run karma"
},
Expand Down
1 change: 0 additions & 1 deletion src/core/base-runner.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import "./include-config.js";
import "./override-configuration.js";
import "./respec-ready.js";
import "./jquery-enhanced.js"; // for backward compatibility
import { done as postProcessDone } from "./post-process.js";
import { done as preProcessDone } from "./pre-process.js";
import { pub } from "./pubsubhub.js";
Expand Down
2 changes: 1 addition & 1 deletion tests/spec/SpecHelper.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const iframes = [];
* @return {Promise<Document>}
*/
export function makeRSDoc(opts, src, style = "") {
opts = { profile: "w3c-common", ...opts };
opts = { profile: "w3c", ...opts };
return new Promise((resolve, reject) => {
const ifr = document.createElement("iframe");
// reject when DEFAULT_TIMEOUT_INTERVAL passes
Expand Down
2 changes: 1 addition & 1 deletion tests/spec/core/highlight.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<head>
<meta charset='utf-8'>
<title>Replace me with a real title</title>
<script class='remove' src='/builds/respec-w3c-common.js'></script>
<script class='remove' src='/builds/respec-w3c.js'></script>
<script class='remove'>
async function loadSolidity() {
const worker = await new Promise(resolve => {
Expand Down
2 changes: 1 addition & 1 deletion tests/spec/core/pubsubhub-spec.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<!DOCTYPE html>
<meta charset="utf-8" />
<script src="/builds/respec-w3c-common.js"></script>
<script src="/builds/respec-w3c.js"></script>
<script class='remove'>
const respecConfig = {
specStatus: "unofficial",
Expand Down
4 changes: 2 additions & 2 deletions tests/spec/core/simple.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
<title>Simple Spec</title>
<script class='remove'>
const script = document.createElement("script");
script.dataset.main = "/js/profile-w3c-common";
script.dataset.main = "/js/profile-w3c";
script.classList.add("remove");
script.src = window.__karma__ ?
"/builds/respec-w3c-common.js"
"/builds/respec-w3c.js"
: "/js/deps/require.js";
document.head.appendChild(script);
</script>
Expand Down
41 changes: 17 additions & 24 deletions tests/test-build.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,38 +2,31 @@
/* eslint-env node */

"use strict";
const fsp = require("fs-extra");
const fs = require("fs");
const { promisify } = require("util");
const readFile = promisify(fs.readFile);
const lstat = promisify(fs.lstat);
const path = require("path");
const expect = require("chai").expect;
const { Builder } = require("../tools/builder");

async function checkIfFileExists(filePath) {
const stats = await fsp.lstat(filePath);
const stats = await lstat(filePath);
return stats.isFile();
}

describe("builder (tool)", () => {
it("builds w3c respec", async () => {
const profileFile = path.join(__dirname, "../builds/respec-w3c-common.js");
const mapFile = path.join(__dirname, "../builds/respec-w3c-common.js.map");
await Builder.build({ name: "w3c-common" });
expect(await checkIfFileExists(profileFile)).to.equal(true);
expect(await checkIfFileExists(mapFile)).to.equal(true);
});

it("builds Geonovum profile", async () => {
const profileFile = path.join(__dirname, "../builds/respec-geonovum.js");
const mapFile = path.join(__dirname, "../builds/respec-geonovum.js.map");
await Builder.build({ name: "geonovum" });
expect(await checkIfFileExists(profileFile)).to.equal(true);
expect(await checkIfFileExists(mapFile)).to.equal(true);
});

describe("respec-w3c-common.build.js", () => {
const latest = path.join(__dirname, "../builds/respec-w3c-common.js");
it("should include the link to the sourcemap", async () => {
const source = await fsp.readFile(latest, "utf-8");
expect(source.search("respec-w3c-common.js.map")).to.not.equal(-1);
for (const profile of ["w3c-common", "w3c", "geonovum"]) {
const profileFile = path.join(__dirname, `../builds/respec-${profile}.js`);
const mapFile = path.join(__dirname, `../builds/respec-${profile}.js.map`);
it(`builds the "${profile}" profile and sourcemap`, async () => {
await Builder.build({ name: profile });
expect(await checkIfFileExists(profileFile)).to.equal(true);
expect(await checkIfFileExists(mapFile)).to.equal(true);
});
it(`includes sourcemap link for "${profile}"`, async () => {
const source = await readFile(profileFile, "utf-8");
expect(source.includes(`${profile}.js.map`)).to.equal(true);
});
});
}
});
Loading

0 comments on commit 3ed6dc6

Please sign in to comment.