chore(test): make tests run again on older browsers

When removing unnecessary dependencies, polyfills like core-js were
removed, as well as webpack which bundled the tests to es5. With this
commit, tests that need specific browser features are skipped if the
browser does not support them and the code is compiled to es5 by
karma-typescript
pull/948/head
Jan van Brügge 4 years ago
parent 795e9968d9
commit 0e34828632
No known key found for this signature in database
GPG Key ID: 88E0BF7B7A546481

@ -15,7 +15,7 @@ jobs:
- run: npm ci - run: npm ci
- run: npm test - run: npm run test:ci
env: env:
BROWSER_STACK_USERNAME: ${{ secrets.BROWSER_STACK_USERNAME }} BROWSER_STACK_USERNAME: ${{ secrets.BROWSER_STACK_USERNAME }}
BROWSER_STACK_ACCESS_KEY: ${{ secrets. BROWSER_STACK_ACCESS_KEY }} BROWSER_STACK_ACCESS_KEY: ${{ secrets. BROWSER_STACK_ACCESS_KEY }}

@ -90,6 +90,7 @@ module.exports = {
browser_version: "11.0", browser_version: "11.0",
os: "Windows", os: "Windows",
os_version: "7", os_version: "7",
es5: true,
}, },
BS_IE_10: { BS_IE_10: {
base: "BrowserStack", base: "BrowserStack",
@ -97,5 +98,6 @@ module.exports = {
browser_version: "10.0", browser_version: "10.0",
os: "Windows", os: "Windows",
os_version: "7", os_version: "7",
es5: true,
}, },
}; };

@ -1,6 +1,7 @@
const ci = !!process.env.CI; const ci = !!process.env.CI;
const watch = !!process.env.WATCH; const watch = !!process.env.WATCH;
const live = !!process.env.LIVE; const live = !!process.env.LIVE;
const es5 = !!process.env.ES5;
const ip = "bs-local.com"; const ip = "bs-local.com";
@ -9,8 +10,11 @@ const browserstack = require("./browserstack-karma.js");
// https://www.browserstack.com/open-source (text search "parallels") // https://www.browserstack.com/open-source (text search "parallels")
const BROWSERSTACK_OPEN_SOURCE_CONCURRENCY = 5; const BROWSERSTACK_OPEN_SOURCE_CONCURRENCY = 5;
const getBrowserstackBrowsers = () =>
Object.keys(browserstack).filter((k) => !!browserstack[k].es5 === es5);
const browsers = ci const browsers = ci
? Object.keys(browserstack) ? getBrowserstackBrowsers()
: live : live
? undefined ? undefined
: watch : watch
@ -43,6 +47,12 @@ module.exports = function (config) {
compilerOptions: { compilerOptions: {
...require("./tsconfig.json").compilerOptions, ...require("./tsconfig.json").compilerOptions,
...require("./test/tsconfig.json").compilerOptions, ...require("./test/tsconfig.json").compilerOptions,
sourceMap: false,
inlineSourceMap: true,
target: es5 ? "es5" : "es6",
},
bundlerOptions: {
sourceMap: true,
}, },
include: process.env.FILES_PATTERN.split(",").concat("src/**/*.ts"), include: process.env.FILES_PATTERN.split(",").concat("src/**/*.ts"),
}, },

@ -33,6 +33,7 @@
"unit": "cross-env FILES_PATTERN=\"test/unit/*.ts,test/unit/*.tsx\" karma start karma.conf.js", "unit": "cross-env FILES_PATTERN=\"test/unit/*.ts,test/unit/*.tsx\" karma start karma.conf.js",
"benchmark": "cross-env FILES_PATTERN=\"test-bundles/benchmark/**/*.js\" karma start karma.conf.cjs --concurrency=1", "benchmark": "cross-env FILES_PATTERN=\"test-bundles/benchmark/**/*.js\" karma start karma.conf.cjs --concurrency=1",
"release": "release-it", "release": "release-it",
"test:ci": "npm test && cross-env ES5=true npm run unit",
"test": "npm run build && npm run lint && npm run unit" "test": "npm run build && npm run lint && npm run unit"
}, },
"devDependencies": { "devDependencies": {

@ -41,15 +41,7 @@ function map(fn: any, list: any[]) {
const inner = prop("innerHTML"); const inner = prop("innerHTML");
class A extends HTMLParagraphElement {}
class B extends HTMLParagraphElement {}
describe("snabbdom", function () { describe("snabbdom", function () {
before(function () {
customElements.define("p-a", A, { extends: "p" });
customElements.define("p-b", B, { extends: "p" });
});
let elm: any, vnode0: any; let elm: any, vnode0: any;
beforeEach(function () { beforeEach(function () {
elm = document.createElement("div"); elm = document.createElement("div");
@ -199,13 +191,11 @@ describe("snabbdom", function () {
it("handles classes from both selector and property", function () { it("handles classes from both selector and property", function () {
elm = patch(vnode0, h("div", [h("i.has", { class: { classes: true } })])) elm = patch(vnode0, h("div", [h("i.has", { class: { classes: true } })]))
.elm; .elm;
assert(elm.firstChild.classList.contains("has")); assert(elm.firstChild.classList.contains("has"), "has `has` class");
assert(elm.firstChild.classList.contains("classes")); assert(
}); elm.firstChild.classList.contains("classes"),
it("can create custom elements", function () { "has `classes` class"
const vnode1 = h("p", { is: "p-a" }); );
elm = patch(vnode0, vnode1).elm;
assert(elm instanceof A);
}); });
it("can create elements with text content", function () { it("can create elements with text content", function () {
elm = patch(vnode0, h("div", ["I am a string"])).elm; elm = patch(vnode0, h("div", ["I am a string"])).elm;
@ -378,6 +368,32 @@ describe("snabbdom", function () {
patch(vnode1, vnode2); patch(vnode1, vnode2);
assert.strictEqual((elm as any).a, "foo"); assert.strictEqual((elm as any).a, "foo");
}); });
describe("custom elements", function () {
if ("customElements" in window) {
describe("customized built-in element", function () {
const isSafari = /^((?!chrome|android).)*safari/i.test(
navigator.userAgent
);
if (!isSafari) {
class A extends HTMLParagraphElement {}
class B extends HTMLParagraphElement {}
before(function () {
if ("customElements" in window) {
customElements.define("p-a", A, { extends: "p" });
customElements.define("p-b", B, { extends: "p" });
}
});
it("can create custom elements", function () {
if ("customElements" in window) {
const vnode1 = h("p", { is: "p-a" });
elm = patch(vnode0, vnode1).elm;
assert(elm instanceof A);
} else {
this.skip();
}
});
it("handles changing is attribute", function () { it("handles changing is attribute", function () {
const vnode1 = h("p", { is: "p-a" }); const vnode1 = h("p", { is: "p-a" });
const vnode2 = h("p", { is: "p-b" }); const vnode2 = h("p", { is: "p-b" });
@ -387,6 +403,18 @@ describe("snabbdom", function () {
elm = patch(vnode1, vnode2).elm; elm = patch(vnode1, vnode2).elm;
assert(elm instanceof B); assert(elm instanceof B);
}); });
} else {
it.skip("safari does not support customized built-in elements", () => {
assert(false);
});
}
});
} else {
it.skip("browser does not support custom elements", () => {
assert(false);
});
}
});
describe("using toVNode()", function () { describe("using toVNode()", function () {
it("can remove previous children of the root element", function () { it("can remove previous children of the root element", function () {
const h2 = document.createElement("h2"); const h2 = document.createElement("h2");

Loading…
Cancel
Save