Skip to content

Commit

Permalink
Merge pull request #482 from foretagsplatsen/32129139/Try_jest_jsdom_…
Browse files Browse the repository at this point in the history
…majestic_instead_of_jasmine_in_widgetjs

32129139: Use jest+jsdom+majestic instead of jasmine in widgetjs
  • Loading branch information
DamienCassou authored Apr 11, 2024
2 parents b45a487 + 10544f8 commit 2343bdb
Show file tree
Hide file tree
Showing 21 changed files with 2,464 additions and 772 deletions.
3 changes: 2 additions & 1 deletion .eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ module.exports = {
// workaround for plugin:@foretagsplatsen/main enabling many
// unwanted environments:
env: { amd: false, jquery: false, node: false, jasmine: false },
ignorePatterns: ["sample"],
ignorePatterns: ["sample", "coverage"],
rules: {
"import/no-unused-modules": [
"error",
Expand All @@ -18,6 +18,7 @@ module.exports = {
"src/widgetjs.js",
// List of files not exporting anything:
"**/.eslintrc.cjs",
"./babel.config.cjs",
"src/router/optionalParameterSegment.js",
"src/router/staticSegment.js",
],
Expand Down
11 changes: 11 additions & 0 deletions babel.config.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/* eslint-env node */

module.exports = {
overrides: [
{
env: {
test: { plugins: ["@babel/plugin-transform-modules-commonjs"] },
},
},
],
};
18 changes: 0 additions & 18 deletions jasmine-browser.json

This file was deleted.

29 changes: 29 additions & 0 deletions jest.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/**
* For a detailed explanation regarding each configuration property, visit:
* https://jestjs.io/docs/configuration
*/

/** @type {import('jest').Config} */
const config = {
restoreMocks: true,

testRegex: ["./src/test/.*Test.js"],

setupFilesAfterEnv: ["./src/test/setup.js"],

// Use "jsdom" instead of "node" to have a "window" object in the
// global environment:
testEnvironment: "jsdom",

collectCoverage: true,
collectCoverageFrom: ["./src/**", "!./src/test/**", "!./src/widgetjs.js"],
coverageDirectory: "coverage",

// Files from node_modules/ are normally not transformed but we
// need to convert some of them anyway as they only provide ES
// modules which is not compatible with Jest
// https://jestjs.io/docs/ecmascript-modules:
transformIgnorePatterns: ["/node_modules/(?!(klassified|yaem))"],
};

export default config;
14 changes: 9 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,19 @@
},
"scripts": {
"lint": "eslint --max-warnings 0 --format unix --report-unused-disable-directives .",
"test:run": "jasmine-browser-runner runSpecs --config=jasmine-browser.json",
"test:serve": "jasmine-browser-runner serve --config=jasmine-browser.json --port=8881"
"test:run": "jest",
"test:serve": "majestic"
},
"devDependencies": {
"@babel/core": "^7.24.4",
"@babel/plugin-transform-modules-commonjs": "^7.24.1",
"@foretagsplatsen/eslint-plugin": "^6.0.0",
"@jest/globals": "^29.7.0",
"eslint": "^8.57.0",
"jasmine-core": "^5.1.2",
"jasmine-browser-runner": "^2.4.0",
"jasmine-reporters": "^2.5.2",
"jest": "^29.7.0",
"jest-environment-jsdom": "^29.7.0",
"jest-extended": "^4.0.2",
"majestic": "^1.8.1",
"yaem": "foretagsplatsen/yaem#1.0.0"
},
"peerDependencies": {
Expand Down
2 changes: 1 addition & 1 deletion src/Widget2.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import router from "./router.js";
import { eventCategory } from "yaem";
import htmlCanvas from "./htmlCanvas.js";
import jQuery from "./lib-wrappers/jquery.js";
import jQuery from "jquery";
import { getCurrentWidget, withCurrentWidget } from "./currentWidget.js";
import { newId } from "./idGenerator.js";

Expand Down
4 changes: 2 additions & 2 deletions src/htmlCanvas.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import jQuery from "./lib-wrappers/jquery.js";
import classNames from "./lib-wrappers/classnames.js";
import jQuery from "jquery";
import classNames from "classnames";

/**
* @typedef {function} renderer
Expand Down
2 changes: 0 additions & 2 deletions src/lib-wrappers/README.md

This file was deleted.

3 changes: 0 additions & 3 deletions src/lib-wrappers/classnames.js

This file was deleted.

3 changes: 0 additions & 3 deletions src/lib-wrappers/jquery.js

This file was deleted.

2 changes: 1 addition & 1 deletion src/router/hashLocation.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import jQuery from "../lib-wrappers/jquery.js";
import jQuery from "jquery";
import { eventCategory } from "yaem";
import url from "./url.js";
import { object } from "klassified";
Expand Down
2 changes: 1 addition & 1 deletion src/router/url.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { object } from "klassified";
import jQuery from "../lib-wrappers/jquery.js";
import jQuery from "jquery";

/**
* Token/Char used to separate segments in URL paths.
Expand Down
1 change: 0 additions & 1 deletion src/test/.eslintrc.cjs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
/* eslint-env commonjs */

module.exports = {
env: { jasmine: true },
rules: {
"import/no-unused-modules": "off",
},
Expand Down
Loading

0 comments on commit 2343bdb

Please sign in to comment.