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

Fix-karma #1157

Closed
wants to merge 8 commits into from
Closed
Show file tree
Hide file tree
Changes from 5 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
41 changes: 29 additions & 12 deletions karma.conf.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Karma configuration
// Generated on Sat Jan 28 2017 19:40:10 GMT-0300 (BRT)
const { execSync } = require("child_process");
const NodePolyfillPlugin = require("node-polyfill-webpack-plugin");

const allowed = `?(${execSync("ls packages", { encoding: "utf8" })
.trim()
Expand All @@ -14,15 +15,37 @@ module.exports = function (config) {

// frameworks to use
// available frameworks: https://npmjs.org/browse/keyword/karma-adapter
frameworks: ["browserify", "mocha"],
frameworks: ["mocha", "webpack"],

browserify: {
debug: true,
transform: ["babelify"],
plugins: [
"karma-webpack",
"karma-mocha",
"karma-mocha-reporter",
"karma-chrome-launcher",
"karma-firefox-launcher",
],

logLevel: config.DEBUG,

colors: true,

webpack: {
// For configuration
// https://www.npmjs.com/package/karma-webpack
target: "web",
devtool: "inline-source-map",
mode: "development",
resolve: {
fallback: {
fs: false,
path: require.resolve("path-browserify"),
},
},
plugins: [new NodePolyfillPlugin()],
},

preprocessors: {
[`packages/${allowed}/test/**/*.js`]: "browserify",
[`packages/${allowed}/test/**/*.js`]: ["webpack"],
},

// list of files / patterns to load in the browser
Expand All @@ -46,14 +69,8 @@ module.exports = function (config) {
"/packages/plugin-print/fonts/": "/base/packages/plugin-print/fonts/",
},

// level of logging
// possible values: config.LOG_DISABLE || config.LOG_ERROR || config.LOG_WARN || config.LOG_INFO || config.LOG_DEBUG
logLevel: config.LOG_INFO,

// start these browsers
// available browser launchers: https://npmjs.org/browse/keyword/karma-launcher
browsers: ["Firefox", "Chrome"],

reporters: ["mocha"],
browsers: ["Chrome", "Firefox"],
});
};
17 changes: 10 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"lint": "eslint --ext .js,.ts,.tsx '**/*.{js,ts}'",
"test": "cross-env BABEL_ENV=test mocha --require @babel/register './packages/**/test/**/*.test.js' --require ts-node/register ./packages/**/test/*.test.ts",
"test:watch": "npm run test -- --reporter min --watch",
"test:browser": "cross-env BABEL_ENV=test ENV=browser CHROME_BIN=\"$(which chrome || which chromium)\" karma start --single-run",
"test:browser": "cross-env BABEL_ENV=test ENV=browser karma start --single-run",
"test:browser:watch": "npm run -s test:browser start -- --auto-watch",
"clean": "lerna clean --yes && rm -rf node_modules && npm run clean:build",
"clean:build": "rm -rf packages/**/es packages/**/dist",
Expand All @@ -42,6 +42,8 @@
"babel-plugin-add-module-exports": "^1.0.4",
"babel-plugin-source-map-support": "^2.2.0",
"babel-plugin-transform-inline-environment-variables": "^0.4.3",
"babelify": "^10.0.0",
"browserify": "^17.0.0",
"cross-env": "^6.0.0",
"dtslint": "^4.2.1",
"eslint": "^8.27.0",
Expand All @@ -50,11 +52,11 @@
"eslint-plugin-import": "^2.27.5",
"express": "^4.17.1",
"husky": "^3.0.5",
"karma": "^4.3.0",
"karma-browserify": "^6.1.0",
"karma-chrome-launcher": "^3.1.0",
"karma-firefox-launcher": "^1.2.0",
"karma-mocha": "^1.3.0",
"karma": "^6.4.1",
"karma-browserify": "^8.1.0",
"karma-chrome-launcher": "^3.1.1",
"karma-firefox-launcher": "^2.1.2",
"karma-mocha": "^2.0.1",
"karma-mocha-reporter": "^2.2.5",
"lerna": "^3.16.4",
"lint-staged": "^9.2.5",
Expand All @@ -63,7 +65,8 @@
"patch-package": "^6.5.1",
"prettier": "^2.8.3",
"should": "^13.2.3",
"source-map-support": "^0.5.21"
"source-map-support": "^0.5.21",
"watchify": "^4.0.0"
},
"husky": {
"hooks": {
Expand Down
3 changes: 2 additions & 1 deletion packages/test-utils/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ export function hashForEach(hash, func) {
}

export function getTestDir(dir) {
const testRE = /\/[^/]+\.test\.js($|\?.*)/;
// Legacy webpack support. I do not know the exact purpose of this file
nopeless marked this conversation as resolved.
Show resolved Hide resolved
const testRE = /\/[^/]+\.test\.(?:\d+\.)?js($|\?.*)/;
if (
typeof document !== "undefined" &&
document &&
Expand Down
24 changes: 22 additions & 2 deletions packages/test-utils/src/jgd-wrapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,28 @@ function configureJimp() {
});
}

const Jimp =
typeof window !== "undefined" && window.Jimp ? window.Jimp : configureJimp();
/**
* The ultimate hack
nopeless marked this conversation as resolved.
Show resolved Hide resolved
*/
function chaos(J) {
if (J.__esModule) {
return chaos(J.default || J.Jimp);
}

if (J.Jimp) {
return chaos(J.Jimp);
}

if (J.default) {
return chaos(J.default);
}

return J;
}

const Jimp = chaos(
typeof window !== "undefined" && window.Jimp ? window.Jimp : configureJimp()
);

/**
* Jimp constructor (from a JGD object)
Expand Down
Loading