Skip to content

Commit

Permalink
[IMP] devtools: introduce basic testing infrastructure
Browse files Browse the repository at this point in the history
  • Loading branch information
sdegueldre committed Jul 5, 2023
1 parent 432ff44 commit b153273
Show file tree
Hide file tree
Showing 13 changed files with 313 additions and 81 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
/node_modules
/dist
# compiled devtools files
/tools/devtools/assets/*.js

npm-debug.log

Expand Down
22 changes: 22 additions & 0 deletions jest.config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"testEnvironment": "jsdom",
"roots": [
"<rootDir>/tests"
],
"setupFiles": [
"./tests/mocks/mockEventTarget.js"
],
"transform": {
"^.+\\.ts?$": "ts-jest"
},
"verbose": false,
"testRegex": "(/tests/.*(test|spec))\\.ts?$",
"moduleFileExtensions": [
"ts",
"tsx",
"js",
"jsx",
"json",
"node"
]
}
40 changes: 40 additions & 0 deletions package-lock.json

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

37 changes: 9 additions & 28 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,19 @@
"dev:devtools-firefox": "npm run build:devtools -- --config-browser=firefox",
"build:devtools-chrome": "npm run dev:devtools-chrome -- --config-env=production",
"build:devtools-firefox": "npm run dev:devtools-firefox -- --config-env=production",
"test": "jest",
"test:debug": "node --inspect-brk node_modules/.bin/jest --runInBand --watch --testTimeout=5000000",
"test:watch": "jest --watch",
"test-owl": "jest",
"test-owl:debug": "node --inspect-brk node_modules/.bin/jest --runInBand --watch --testTimeout=5000000",
"test-owl:watch": "jest --watch",
"test-devtools": "npm run build:devtools-chrome && jest --config=tools/devtools/tests/jest.config.json",
"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",
"test-devtools:watch": "jest --config=tools/devtools/tests/jest.config.json --watch",
"test": "npm run test-owl && npm run test-devtools",
"playground:serve": "python3 tools/playground_server.py || python tools/playground_server.py",
"playground": "npm run build && npm run playground:serve",
"preplayground:watch": "npm run build",
"playground:watch": "npm-run-all --parallel playground:serve \"build:* -- --watch\"",
"prettier": "prettier {src/*.ts,src/**/*.ts,tests/*.ts,tests/**/*.ts,doc/*.md,doc/**/*.md,tools/devtools/**/*.js} --write",
"check-formatting": "prettier {src/*.ts,src/**/*.ts,tests/*.ts,tests/**/*.ts,doc/*.md,doc/**/*.md,tools/devtools/**/*.js} --check",
"check-formatting": "npm run prettier -- --check",
"lint": "eslint src/**/*.ts tests/**/*.ts",
"release": "node tools/release.js",
"compile_templates": "node tools/compile_xml.js"
Expand All @@ -55,13 +59,13 @@
"git-rev-sync": "^3.0.2",
"github-api": "^3.3.0",
"jest": "^27.1.0",
"jest-chrome": "^0.8.0",
"jest-diff": "^27.3.1",
"jest-environment-jsdom": "^27.1.0",
"npm-run-all": "^4.1.5",
"prettier": "2.4.1",
"rollup": "^2.56.3",
"rollup-plugin-copy": "^3.3.0",
"rollup-plugin-delete": "^2.0.0",
"rollup-plugin-dts": "^4.2.2",
"rollup-plugin-execute": "^1.1.1",
"rollup-plugin-string": "^3.0.0",
Expand All @@ -71,29 +75,6 @@
"ts-jest": "^27.0.5",
"typescript": "4.5.2"
},
"jest": {
"testEnvironment": "jsdom",
"roots": [
"<rootDir>/src",
"<rootDir>/tests"
],
"setupFiles": [
"./tests/mocks/mockEventTarget.js"
],
"transform": {
"^.+\\.ts?$": "ts-jest"
},
"verbose": false,
"testRegex": "(/tests/.*(test|spec))\\.ts?$",
"moduleFileExtensions": [
"ts",
"tsx",
"js",
"jsx",
"json",
"node"
]
},
"prettier": {
"printWidth": 100,
"endOfLine": "auto"
Expand Down
22 changes: 9 additions & 13 deletions tools/devtools/rollup.config.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import terser from "rollup-plugin-terser";
import copy from "rollup-plugin-copy";
import execute from "rollup-plugin-execute";
import del from "rollup-plugin-delete";
import { string } from "rollup-plugin-string";

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

function generateRule(input, format = "esm") {
function generateRule(input, plugins = []) {
return {
input: input,
input,
output: [
{
format: format,
format: "esm",
file: input.replace("tools/devtools/src", "dist/devtools"),
},
],
Expand All @@ -51,14 +50,14 @@ export default ({ "config-browser": browser, "config-env": env }) => {
include: "**/page_scripts/owl_devtools_global_hook.js",
}),
isProduction && terser.terser(),
...plugins,
],
};
}
const commands = new Array(2);
commands[1] = isWindows
? "npm run compile_templates -- tools\\devtools\\src && move templates.js tools\\devtools\\assets\\templates.js"
: "npm run compile_templates -- tools/devtools/src && mv templates.js tools/devtools/assets/templates.js";
const firstRule = generateRule("tools/devtools/src/page_scripts/owl_devtools_global_hook.js");
if (isProduction) {
commands[0] = isWindows
? "npm run build && copy dist\\owl.iife.js tools\\devtools\\assets\\owl.js && npm run build:compiler"
Expand All @@ -68,19 +67,16 @@ export default ({ "config-browser": browser, "config-env": env }) => {
? "copy dist\\owl.iife.js tools\\devtools\\assets\\owl.js"
: "cp dist/owl.iife.js tools/devtools/assets/owl.js";
}
firstRule.plugins.push(execute(commands, true));
const secondRule = generateRule("tools/devtools/src/content.js");
secondRule.plugins.push(copy({ targets: filesToMove }));
const lastRule = generateRule("tools/devtools/src/background.js");
lastRule.plugins.push(del({ targets: "tools/devtools/assets/*.js" }));

return [
firstRule,
secondRule,
generateRule("tools/devtools/src/page_scripts/owl_devtools_global_hook.js", [
execute(commands, true),
]),
generateRule("tools/devtools/src/content.js", [copy({ targets: filesToMove })]),
generateRule("tools/devtools/src/devtools_app/devtools.js"),
generateRule("tools/devtools/src/utils.js"),
generateRule("tools/devtools/src/devtools_app/devtools_panel.js"),
generateRule("tools/devtools/src/popup_app/popup.js"),
lastRule,
generateRule("tools/devtools/src/background.js"),
];
};
2 changes: 2 additions & 0 deletions tools/devtools/src/devtools_app/devtools_panel.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@
import { DevtoolsWindow } from "./devtools_window/devtools_window";
const { mount } = owl;
import { templates } from "../../assets/templates.js";
import { createStore } from "./store/store";

for (const template in templates) {
owl.App.registerTemplate(template, templates[template]);
}
createStore();
mount(DevtoolsWindow, document.body, { dev: true });
4 changes: 1 addition & 3 deletions tools/devtools/src/devtools_app/store/store.js
Original file line number Diff line number Diff line change
Expand Up @@ -625,9 +625,7 @@ export function useStore() {
return useState(store);
}

init();

async function init() {
export async function createStore() {
store.devtoolsId = await getTabURL();

evalFunctionInWindow("initDevtools", []);
Expand Down
Loading

0 comments on commit b153273

Please sign in to comment.