Add a separate tsconfig for tests

Tests run with nodejs + jest types, while the web extension code
runs with browser + web-ext type roots.
This commit is contained in:
Jakub Okoński 2019-10-18 13:05:37 +02:00
parent bd2b988338
commit 67fa18b4ec
7 changed files with 54 additions and 23 deletions

View file

@ -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

View file

@ -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/

View file

@ -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.

View file

@ -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, "<Tab><CR>")
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)

View file

@ -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"
]
}

26
tsconfig.test.json Normal file
View file

@ -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"
]
}

View file

@ -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"