Skip to content

Debug CI tests #5

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

Open
wants to merge 16 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions .github/workflows/CI-CD.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ jobs:
- macos-latest
- windows-latest
node:
- 14
- 17
- lts/*
- current

Expand Down Expand Up @@ -65,6 +65,7 @@ jobs:
matrix:
os:
- ubuntu-latest # Chrome, Firefox
- macos-latest # Safari
- windows-latest # Internet Explorer

steps:
Expand All @@ -81,9 +82,6 @@ jobs:

- name: Run tests
run: npm run coverage:browser
env:
SAUCE_USERNAME: ${{ secrets.SAUCE_USERNAME }}
SAUCE_ACCESS_KEY: ${{ secrets.SAUCE_ACCESS_KEY }}

- name: Combine code coverage data into a single file
shell: bash
Expand Down
78 changes: 65 additions & 13 deletions karma.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,70 @@

"use strict";

const { karmaConfig } = require("@jsdevtools/karma-config");
const nodeUtil = require("util");
const { buildConfig } = require("@jsdevtools/karma-config");
const { host } = require("@jsdevtools/host-environment");

module.exports = karmaConfig({
sourceDir: "lib",
fixtures: "test/fixtures/**/*.js",
browsers: {
chrome: host.ci ? host.os.linux : true,
firefox: host.ci ? host.os.linux : true,
// TODO these were disabled as unstable. should we remove saucelabs or what?
// safari: host.ci ? host.os.linux : host.os.mac, // SauceLabs in CI
edge: host.ci ? host.os.linux : host.os.windows, // SauceLabs in CI
// ie: host.ci ? host.os.windows : false, // IE needs to run by itself, due to Babel transforms
},
});
module.exports = (karma) => {

const browsers = [];
const CI = isCI();
browsers.push(CI ? "ChromeHeadless" : "Chrome");
browsers.push(CI ? "FirefoxHeadless" : "Firefox");
host.os.mac && browsers.push("Safari");
host.os.windows && browsers.push("Edge");

const plugins = [
require("@jsdevtools/karma-host-environment"),
require("karma-verbose-reporter"),
require("karma-mocha"),
require("karma-webpack"),
]
plugins.push(require("karma-chrome-launcher"))
plugins.push(require("karma-firefox-launcher"))
host.os.mac && plugins.push(require("karma-safari-launcher"))
host.os.windows && plugins.push(require("@chiragrupani/karma-chromium-edge-launcher"))
plugins.push(require("karma-coverage-istanbul-reporter"))

const config = buildConfig({
sourceDir: "lib",
fixtures: "test/fixtures/**/*.js",
browsers: {
chrome: true,
firefox: true,
safari: host.os.mac,
edge: host.os.windows,
ie: false
},
config: {
browsers: browsers,
plugins: plugins
}
});

if (config.logLevel !== karma.LOG_DISABLE) {
console.debug("Karma Config:\n", nodeUtil.inspect(config, {
depth: 10,
colors: true,
compact: false,
}));
}

karma.set(config);
};

function isCI() {
let CI = environmentFlag("CI");
let karmaCI = environmentFlag("KARMA_CI");

return Boolean(CI || karmaCI || host.ci);
};

function environmentFlag(name) {
let value = environmentVariable(name);
return !["", "false", "off", "no"].includes(value);
}

function environmentVariable(name) {
return (process.env[name] || "").trim().toLowerCase();
}
2 changes: 1 addition & 1 deletion lib/refs.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const { ono } = require("@jsdevtools/ono");
const $Ref = require("./ref");
const url = require("./util/url");

const isWindows = /^win/.test(globalThis.process?.platform);
const isWindows = /^win/.test(globalThis.process ? globalThis.process.platform : undefined);
const getPathFromOs = filePath => isWindows ? filePath.replace(/\\/g, "/") : filePath;

module.exports = $Refs;
Expand Down
18 changes: 9 additions & 9 deletions lib/resolvers/http.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ module.exports = {
* @param {object} file - An object containing information about the referenced file
* @param {string} file.url - The full URL of the referenced file
* @param {string} file.extension - The lowercased file extension (e.g. ".txt", ".html", etc.)
* @returns {Promise<string>}
* @returns {Promise<Buffer>}
*/
read (file) {
let u = url.parse(file.url);
Expand All @@ -89,7 +89,7 @@ module.exports = {
* @param {object} httpOptions - The `options.resolve.http` object
* @param {number} [redirects] - The redirect URLs that have already been followed
*
* @returns {Promise<string>}
* @returns {Promise<Buffer>}
* The promise resolves with the raw downloaded data, or rejects if there is an HTTP error.
*/
function download (u, httpOptions, redirects) {
Expand All @@ -99,25 +99,25 @@ function download (u, httpOptions, redirects) {

return get(u, httpOptions)
.then((res) => {
if (res.statusCode >= 400) {
throw ono({ status: res.statusCode }, `HTTP ERROR ${res.statusCode}`);
if (res.status >= 400) {
throw ono({ status: res.statusCode }, `HTTP ERROR ${res.status}`);
}
else if (res.statusCode >= 300) {
else if (res.status >= 300) {
if (redirects.length > httpOptions.redirects) {
throw new ResolverError(ono({ status: res.statusCode },
throw new ResolverError(ono({ status: res.status },
`Error downloading ${redirects[0]}. \nToo many redirects: \n ${redirects.join(" \n ")}`));
}
else if (!res.headers.location) {
throw ono({ status: res.statusCode }, `HTTP ${res.statusCode} redirect with no location header`);
throw ono({ status: res.status }, `HTTP ${res.status} redirect with no location header`);
}
else {
// console.log('HTTP %d redirect %s -> %s', res.statusCode, u.href, res.headers.location);
// console.log('HTTP %d redirect %s -> %s', res.status, u.href, res.headers.location);
let redirectTo = url.resolve(u, res.headers.location);
return download(redirectTo, httpOptions, redirects);
}
}
else {
return res.text();
return res.body ? res.arrayBuffer().then(buf => Buffer.from(buf)) : Buffer.alloc(0);
}
})
.catch((err) => {
Expand Down
2 changes: 1 addition & 1 deletion lib/util/url.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
const nodePath = require("path");
const projectDir = nodePath.resolve(__dirname, "..", "..");

let isWindows = /^win/.test(globalThis.process?.platform),
let isWindows = /^win/.test(globalThis.process ? globalThis.process.platform : undefined),
forwardSlashPattern = /\//g,
protocolPattern = /^(\w{2,}):\/\//i,
url = module.exports,
Expand Down
Loading