From 67fa18b4ec40e84fb30e6aee2c1c8e49cd6ad406 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Oko=C5=84ski?= Date: Fri, 18 Oct 2019 13:05:37 +0200 Subject: [PATCH] Add a separate tsconfig for tests Tests run with nodejs + jest types, while the web extension code runs with browser + web-ext type roots. --- package.json | 6 +++--- scripts/make_docs.sh | 2 +- src/excmds.ts | 2 +- tests/excmds.test.ts | 23 +++++++++++------------ tsconfig.json | 13 +++++++------ tsconfig.test.json | 26 ++++++++++++++++++++++++++ yarn.lock | 5 +++++ 7 files changed, 54 insertions(+), 23 deletions(-) create mode 100644 tsconfig.test.json diff --git a/package.json b/package.json index 604f0f7d..5aad0f0f 100644 --- a/package.json +++ b/package.json @@ -20,6 +20,7 @@ "@types/jest": "^24.0.19", "@types/mithril": "^2.0.0", "@types/node": "^12.11.1", + "@types/selenium-webdriver": "^4.0.5", "awesome-typescript-loader": "^5.2.1", "cleanslate": "^0.10.1", "copy-webpack-plugin": "^5.0.4", @@ -58,9 +59,7 @@ "pretty": "bash scripts/pretty.sh" }, "jest": { - "transform": { - "^.+\\.tsx?$": "ts-jest" - }, + "preset": "ts-jest", "testRegex": "(/__tests__/.*|(\\.|/)(test|spec))\\.(jsx?|tsx?)$", "moduleFileExtensions": [ "ts", @@ -74,6 +73,7 @@ }, "globals": { "ts-jest": { + "tsConfig": "tsconfig.test.json", "diagnostics": { "ignoreCodes": [ 151001 diff --git a/scripts/make_docs.sh b/scripts/make_docs.sh index 882f7345..161e8232 100755 --- a/scripts/make_docs.sh +++ b/scripts/make_docs.sh @@ -1,4 +1,4 @@ #!/bin/sh dest=generated/static/docs -"$(yarn bin)/typedoc" --theme src/static/typedoc/ --out $dest src --ignoreCompilerErrors +"$(yarn bin)/typedoc" --theme src/static/typedoc/ --exclude "src/**/?(test_utils|*.test).ts" --out $dest src --ignoreCompilerErrors cp -r $dest build/static/ diff --git a/src/excmds.ts b/src/excmds.ts index 201975a3..52ba92c0 100644 --- a/src/excmds.ts +++ b/src/excmds.ts @@ -861,7 +861,7 @@ let JUMPED: boolean /** @hidden */ //#content_helper -let JUMP_TIMEOUTID +let JUMP_TIMEOUTID: number | undefined /** This is used as an ID for the current page in the jumplist. It has a potentially confusing behavior: if you visit site A, then site B, then visit site A again, the jumplist that was created for your first visit on A will be re-used for your second visit. diff --git a/tests/excmds.test.ts b/tests/excmds.test.ts index 200f4d14..28e639cc 100644 --- a/tests/excmds.test.ts +++ b/tests/excmds.test.ts @@ -1,12 +1,11 @@ -require("geckodriver") +import "geckodriver" -const fs = require("fs") -const os = require("os") -const path = require("path") -const webdriver = require("selenium-webdriver") -const Until = webdriver.until -const By = webdriver.By -const Options = require("selenium-webdriver/firefox").Options +import * as fs from "fs" +import * as os from "os" +import * as path from "path" +import * as webdriver from "selenium-webdriver" +const {until, By} = webdriver +import {Options} from "selenium-webdriver/firefox" jest.setTimeout(100000) @@ -55,7 +54,7 @@ function sendKeys (driver, keys) { const [modifiers, key] = noBrackets.split("-") const mods = modifiers.split("").map(mod => modToSelenium[mod]) return mods - .reduce((actions, mod) => actions.keyUp(mod), + .reduce((actions, mod) => actions.keyUp(mod), mods.reduce((actions, mod) => actions.keyDown(mod), driver.actions()) .sendKeys(vimToSelenium[key] || key)) .perform() @@ -92,7 +91,7 @@ function sendKeys (driver, keys) { describe("webdriver", () => { function iframeLoaded(driver) { - return driver.wait(Until.elementLocated(By.id("cmdline_iframe"))) + return driver.wait(until.elementLocated(By.id("cmdline_iframe"))) } async function getDriver() { @@ -199,8 +198,8 @@ describe("webdriver", () => { // Then, make sure rsscmd is executed and has the right arguments await sendKeys(driver, "") - await driver.switchTo().parentFrame() - const elem = await driver.wait(Until.elementLocated(By.id("rsscmdExecuted"))) + await (driver.switchTo() as any).parentFrame() + const elem = await driver.wait(until.elementLocated(By.id("rsscmdExecuted"))) expect(url).toMatch(await elem.getAttribute("innerText")) } catch (e) { fail(e) diff --git a/tsconfig.json b/tsconfig.json index 206e6b8d..10575ca4 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -7,18 +7,19 @@ "sourceMap": true, "target": "es2017", "lib": ["es2017","es2019.array","dom", "dom.iterable"], - "typeRoots": ["node_modules/@types", "node_modules/web-ext-types/"], + "types": ["web-ext-types"], "experimentalDecorators": true, "alwaysStrict": true, - "baseUrl": "src/", - "paths": { - "@src/*": ["*"] - } + "baseUrl": "src/", + "paths": { + "@src/*": ["*"] + } }, "include": [ "./src/**/*" ], "exclude": [ - "./src/**/*.test.ts" + "./src/**/*.test.ts", + "./src/lib/test_utils.ts" ] } diff --git a/tsconfig.test.json b/tsconfig.test.json new file mode 100644 index 00000000..cb433ed0 --- /dev/null +++ b/tsconfig.test.json @@ -0,0 +1,26 @@ +{ + "compilerOptions": { + "allowJs": true, + "moduleResolution": "node", + "noImplicitAny": false, + "noEmitOnError": true, + "outDir": "build/tsc-out", + "sourceMap": true, + "target": "es2017", + "lib": ["es2017", "es2019.array", "es2018.promise", "dom", "dom.iterable"], + "typeRoots": ["node_modules/@types"], + "types": ["jest", "node"], + "experimentalDecorators": true, + "alwaysStrict": true, + "baseUrl": "src/", + "paths": { + "@src/*": ["*"] + } + }, + "include": [ + "./src/**/*" + ], + "exclude": [ + "./src/**/*.test.ts" + ] +} diff --git a/yarn.lock b/yarn.lock index 79ff24b5..d2c577fc 100644 --- a/yarn.lock +++ b/yarn.lock @@ -453,6 +453,11 @@ resolved "https://registry.yarnpkg.com/@types/node/-/node-12.11.1.tgz#1fd7b821f798b7fa29f667a1be8f3442bb8922a3" integrity sha512-TJtwsqZ39pqcljJpajeoofYRfeZ7/I/OMUQ5pR4q5wOKf2ocrUvBAZUMhWsOvKx3dVc/aaV5GluBivt0sWqA5A== +"@types/selenium-webdriver@^4.0.5": + version "4.0.5" + resolved "https://registry.yarnpkg.com/@types/selenium-webdriver/-/selenium-webdriver-4.0.5.tgz#23041a4948c82daf2df9836e4d2358fec10d3e24" + integrity sha512-ma1aL1znI3ptEbSQgbywgadrRCJouPIACSfOl/bPwu/TPNSyyE/+o9jZ6+bpDVTtIdksZuVKpq4SR1ip3DRduw== + "@types/stack-utils@^1.0.1": version "1.0.1" resolved "https://registry.yarnpkg.com/@types/stack-utils/-/stack-utils-1.0.1.tgz#0a851d3bd96498fa25c33ab7278ed3bd65f06c3e"