Skip to content

Commit b153273

Browse files
committed
[IMP] devtools: introduce basic testing infrastructure
1 parent 432ff44 commit b153273

File tree

13 files changed

+313
-81
lines changed

13 files changed

+313
-81
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
/node_modules
22
/dist
3+
# compiled devtools files
4+
/tools/devtools/assets/*.js
35

46
npm-debug.log
57

jest.config.json

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
{
2+
"testEnvironment": "jsdom",
3+
"roots": [
4+
"<rootDir>/tests"
5+
],
6+
"setupFiles": [
7+
"./tests/mocks/mockEventTarget.js"
8+
],
9+
"transform": {
10+
"^.+\\.ts?$": "ts-jest"
11+
},
12+
"verbose": false,
13+
"testRegex": "(/tests/.*(test|spec))\\.ts?$",
14+
"moduleFileExtensions": [
15+
"ts",
16+
"tsx",
17+
"js",
18+
"jsx",
19+
"json",
20+
"node"
21+
]
22+
}

package-lock.json

Lines changed: 40 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 9 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,19 @@
2121
"dev:devtools-firefox": "npm run build:devtools -- --config-browser=firefox",
2222
"build:devtools-chrome": "npm run dev:devtools-chrome -- --config-env=production",
2323
"build:devtools-firefox": "npm run dev:devtools-firefox -- --config-env=production",
24-
"test": "jest",
25-
"test:debug": "node --inspect-brk node_modules/.bin/jest --runInBand --watch --testTimeout=5000000",
26-
"test:watch": "jest --watch",
24+
"test-owl": "jest",
25+
"test-owl:debug": "node --inspect-brk node_modules/.bin/jest --runInBand --watch --testTimeout=5000000",
26+
"test-owl:watch": "jest --watch",
27+
"test-devtools": "npm run build:devtools-chrome && jest --config=tools/devtools/tests/jest.config.json",
28+
"test-devtools:debug": "npm run build:devtools-chrome && node --inspect-brk node_modules/.bin/jest --config=tools/devtools/tests/jest.config.json --runInBand --watch --testTimeout=5000000",
29+
"test-devtools:watch": "jest --config=tools/devtools/tests/jest.config.json --watch",
30+
"test": "npm run test-owl && npm run test-devtools",
2731
"playground:serve": "python3 tools/playground_server.py || python tools/playground_server.py",
2832
"playground": "npm run build && npm run playground:serve",
2933
"preplayground:watch": "npm run build",
3034
"playground:watch": "npm-run-all --parallel playground:serve \"build:* -- --watch\"",
3135
"prettier": "prettier {src/*.ts,src/**/*.ts,tests/*.ts,tests/**/*.ts,doc/*.md,doc/**/*.md,tools/devtools/**/*.js} --write",
32-
"check-formatting": "prettier {src/*.ts,src/**/*.ts,tests/*.ts,tests/**/*.ts,doc/*.md,doc/**/*.md,tools/devtools/**/*.js} --check",
36+
"check-formatting": "npm run prettier -- --check",
3337
"lint": "eslint src/**/*.ts tests/**/*.ts",
3438
"release": "node tools/release.js",
3539
"compile_templates": "node tools/compile_xml.js"
@@ -55,13 +59,13 @@
5559
"git-rev-sync": "^3.0.2",
5660
"github-api": "^3.3.0",
5761
"jest": "^27.1.0",
62+
"jest-chrome": "^0.8.0",
5863
"jest-diff": "^27.3.1",
5964
"jest-environment-jsdom": "^27.1.0",
6065
"npm-run-all": "^4.1.5",
6166
"prettier": "2.4.1",
6267
"rollup": "^2.56.3",
6368
"rollup-plugin-copy": "^3.3.0",
64-
"rollup-plugin-delete": "^2.0.0",
6569
"rollup-plugin-dts": "^4.2.2",
6670
"rollup-plugin-execute": "^1.1.1",
6771
"rollup-plugin-string": "^3.0.0",
@@ -71,29 +75,6 @@
7175
"ts-jest": "^27.0.5",
7276
"typescript": "4.5.2"
7377
},
74-
"jest": {
75-
"testEnvironment": "jsdom",
76-
"roots": [
77-
"<rootDir>/src",
78-
"<rootDir>/tests"
79-
],
80-
"setupFiles": [
81-
"./tests/mocks/mockEventTarget.js"
82-
],
83-
"transform": {
84-
"^.+\\.ts?$": "ts-jest"
85-
},
86-
"verbose": false,
87-
"testRegex": "(/tests/.*(test|spec))\\.ts?$",
88-
"moduleFileExtensions": [
89-
"ts",
90-
"tsx",
91-
"js",
92-
"jsx",
93-
"json",
94-
"node"
95-
]
96-
},
9778
"prettier": {
9879
"printWidth": 100,
9980
"endOfLine": "auto"

tools/devtools/rollup.config.js

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import terser from "rollup-plugin-terser";
22
import copy from "rollup-plugin-copy";
33
import execute from "rollup-plugin-execute";
4-
import del from "rollup-plugin-delete";
54
import { string } from "rollup-plugin-string";
65

76
const isWindows = process.platform === "win32";
@@ -37,12 +36,12 @@ export default ({ "config-browser": browser, "config-env": env }) => {
3736
},
3837
];
3938

40-
function generateRule(input, format = "esm") {
39+
function generateRule(input, plugins = []) {
4140
return {
42-
input: input,
41+
input,
4342
output: [
4443
{
45-
format: format,
44+
format: "esm",
4645
file: input.replace("tools/devtools/src", "dist/devtools"),
4746
},
4847
],
@@ -51,14 +50,14 @@ export default ({ "config-browser": browser, "config-env": env }) => {
5150
include: "**/page_scripts/owl_devtools_global_hook.js",
5251
}),
5352
isProduction && terser.terser(),
53+
...plugins,
5454
],
5555
};
5656
}
5757
const commands = new Array(2);
5858
commands[1] = isWindows
5959
? "npm run compile_templates -- tools\\devtools\\src && move templates.js tools\\devtools\\assets\\templates.js"
6060
: "npm run compile_templates -- tools/devtools/src && mv templates.js tools/devtools/assets/templates.js";
61-
const firstRule = generateRule("tools/devtools/src/page_scripts/owl_devtools_global_hook.js");
6261
if (isProduction) {
6362
commands[0] = isWindows
6463
? "npm run build && copy dist\\owl.iife.js tools\\devtools\\assets\\owl.js && npm run build:compiler"
@@ -68,19 +67,16 @@ export default ({ "config-browser": browser, "config-env": env }) => {
6867
? "copy dist\\owl.iife.js tools\\devtools\\assets\\owl.js"
6968
: "cp dist/owl.iife.js tools/devtools/assets/owl.js";
7069
}
71-
firstRule.plugins.push(execute(commands, true));
72-
const secondRule = generateRule("tools/devtools/src/content.js");
73-
secondRule.plugins.push(copy({ targets: filesToMove }));
74-
const lastRule = generateRule("tools/devtools/src/background.js");
75-
lastRule.plugins.push(del({ targets: "tools/devtools/assets/*.js" }));
7670

7771
return [
78-
firstRule,
79-
secondRule,
72+
generateRule("tools/devtools/src/page_scripts/owl_devtools_global_hook.js", [
73+
execute(commands, true),
74+
]),
75+
generateRule("tools/devtools/src/content.js", [copy({ targets: filesToMove })]),
8076
generateRule("tools/devtools/src/devtools_app/devtools.js"),
8177
generateRule("tools/devtools/src/utils.js"),
8278
generateRule("tools/devtools/src/devtools_app/devtools_panel.js"),
8379
generateRule("tools/devtools/src/popup_app/popup.js"),
84-
lastRule,
80+
generateRule("tools/devtools/src/background.js"),
8581
];
8682
};

tools/devtools/src/devtools_app/devtools_panel.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,10 @@
33
import { DevtoolsWindow } from "./devtools_window/devtools_window";
44
const { mount } = owl;
55
import { templates } from "../../assets/templates.js";
6+
import { createStore } from "./store/store";
67

78
for (const template in templates) {
89
owl.App.registerTemplate(template, templates[template]);
910
}
11+
createStore();
1012
mount(DevtoolsWindow, document.body, { dev: true });

tools/devtools/src/devtools_app/store/store.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -625,9 +625,7 @@ export function useStore() {
625625
return useState(store);
626626
}
627627

628-
init();
629-
630-
async function init() {
628+
export async function createStore() {
631629
store.devtoolsId = await getTabURL();
632630

633631
evalFunctionInWindow("initDevtools", []);

0 commit comments

Comments
 (0)