Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 59 additions & 0 deletions experimental/tests.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import { BenchmarkTestStep } from "../resources/benchmark-runner.mjs";
import { todos } from "../resources/translations.mjs";

// TODO: merge with main tests.mjs
const numberOfItemsToAdd = 100;
const defaultLanguage = "en";

function getTodoText(lang, index) {
const todosSelection = todos[lang] ?? todos[defaultLanguage];
const currentIndex = index % todosSelection.length;
return todosSelection[currentIndex];
}

export const ExperimentalSuites = [];

ExperimentalSuites.push({
name: "TodoMVC-LocalStorage",
url: "experimental/todomvc-localstorage/dist/index.html",
tags: ["todomvc", "experimental"],
disabled: true,
async prepare(page) {
(await page.waitForElement(".new-todo")).focus();
page.getLocalStorage().getItem("javascript-es5");
},
tests: [
new BenchmarkTestStep(`Adding${numberOfItemsToAdd}Items`, (page) => {
const newTodo = page.querySelector(".new-todo");
for (let i = 0; i < numberOfItemsToAdd; i++) {
newTodo.setValue(getTodoText("ja", i));
newTodo.dispatchEvent("change");
newTodo.enter("keypress");
}
}),
new BenchmarkTestStep("CompletingAllItems", (page) => {
const checkboxes = page.querySelectorAll(".toggle");
for (let i = 0; i < numberOfItemsToAdd; i++)
checkboxes[i].click();
}),
new BenchmarkTestStep("DeletingAllItems", (page) => {
const deleteButtons = page.querySelectorAll(".destroy");
for (let i = numberOfItemsToAdd - 1; i >= 0; i--)
deleteButtons[i].click();
}),
],
});

ExperimentalSuites.push({
name: "NewsSite-PostMessage",
url: "resources/newssite/news-next/dist/index.html",
tags: ["experimental", "newssite", "language"],
disabled: true,
async prepare() {},
type: "remote",
/* config: {
name: "default", // optional param to target non-default tests locally
}, */
});

Object.freeze(ExperimentalSuites);
48 changes: 3 additions & 45 deletions resources/tests.mjs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { BenchmarkTestStep } from "./benchmark-runner.mjs";
import { todos } from "./translations.mjs";
import { ExperimentalSuites } from "../experimental/tests.mjs";

const numberOfItemsToAdd = 100;
const defaultLanguage = "en";
Expand Down Expand Up @@ -56,37 +57,6 @@ Suites.enable = function (names, tags) {
console.error(message, debugInfo);
};

Suites.push({
name: "TodoMVC-LocalStorage",
url: "experimental/todomvc-localstorage/dist/index.html",
tags: ["todomvc"],
disabled: true,
async prepare(page) {
(await page.waitForElement(".new-todo")).focus();
page.getLocalStorage().getItem("javascript-es5");
},
tests: [
new BenchmarkTestStep(`Adding${numberOfItemsToAdd}Items`, (page) => {
const newTodo = page.querySelector(".new-todo");
for (let i = 0; i < numberOfItemsToAdd; i++) {
newTodo.setValue(getTodoText("ja", i));
newTodo.dispatchEvent("change");
newTodo.enter("keypress");
}
}),
new BenchmarkTestStep("CompletingAllItems", (page) => {
const checkboxes = page.querySelectorAll(".toggle");
for (let i = 0; i < numberOfItemsToAdd; i++)
checkboxes[i].click();
}),
new BenchmarkTestStep("DeletingAllItems", (page) => {
const deleteButtons = page.querySelectorAll(".destroy");
for (let i = numberOfItemsToAdd - 1; i >= 0; i--)
deleteButtons[i].click();
}),
],
});

Suites.push({
name: "TodoMVC-Emoji",
url: "resources/todomvc/vanilla-examples/javascript-web-components/dist/index.html",
Expand Down Expand Up @@ -894,18 +864,6 @@ Suites.push({
],
});

Suites.push({
name: "NewsSite-PostMessage",
url: "resources/newssite/news-next/dist/index.html",
tags: ["experimental", "newssite", "language"],
disabled: true,
async prepare() {},
type: "remote",
/* config: {
name: "default", // optional param to target non-default tests locally
}, */
});

Suites.push({
name: "NewsSite-Nuxt",
url: "resources/newssite/news-nuxt/dist/index.html",
Expand Down Expand Up @@ -1113,12 +1071,12 @@ Suites.push({
],
});

Suites.push(...ExperimentalSuites);

Object.freeze(Suites);
Suites.forEach((suite) => {
if (!suite.tags)
suite.tags = [];
if (suite.url.startsWith("experimental/"))
suite.tags.unshift("all", "experimental");
else if (suite.disabled)
suite.tags.unshift("all");
else
Expand Down
1 change: 1 addition & 0 deletions tests/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@

await import("./unittests/benchmark-runner.mjs");
await import("./unittests/params.mjs");
await import("./unittests/suites.mjs");

globalThis.testResults = undefined;
globalThis.testRunner = mocha.run();
Expand Down
109 changes: 109 additions & 0 deletions tests/unittests/suites.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
import { ExperimentalSuites } from "../../experimental/tests.mjs";
import { Suites } from "../../resources/tests.mjs";

describe("ExperimentalSuites", () => {
it("should be frozen", () => {
expect(Object.isFrozen(ExperimentalSuites)).to.be(true);
});
it("should have tags array", () => {
ExperimentalSuites.forEach((suite) => {
expect(suite.tags).to.be.an("array");
});
});
it("should have frozen tags array", () => {
ExperimentalSuites.forEach((suite) => {
expect(Object.isFrozen(suite.tags)).to.be(true);
});
});
it("should have frozen steps array", () => {
ExperimentalSuites.forEach((suite) => {
expect(Object.isFrozen(suite.tags)).to.be(true);
});
});
it("should have 'experimental' tag", () => {
ExperimentalSuites.forEach((suite) => {
expect(suite.tags.includes("experimental"));
});
});
it("should be disabled by default", () => {
ExperimentalSuites.forEach((suite) => {
expect(suite.disabled).to.be(true);
});
});
it("should have experimental url", () => {
ExperimentalSuites.forEach((suite) => {
expect(suite.url.startsWith("experimental/"));
});
});
it("should have unique names", () => {
const uniqueNames = new Set();
ExperimentalSuites.forEach((suite) => {
expect(uniqueNames.has(suite.name)).to.be(false);
uniqueNames.add(suite.name);
});
});
});

describe("Suites", () => {
it("should be frozen", () => {
expect(Object.isFrozen(Suites)).to.be(true);
});
it("should have tags array", () => {
Suites.forEach((suite) => {
expect(suite.tags).to.be.an("array");
});
});
it("should have frozen tags array", () => {
Suites.forEach((suite) => {
expect(Object.isFrozen(suite.tags)).to.be(true);
});
});
it("should have frozen steps array", () => {
Suites.forEach((suite) => {
expect(Object.isFrozen(suite.tags)).to.be(true);
});
});
it("should have 'all' tags", () => {
Suites.forEach((suite) => {
expect(suite.tags.includes("all")).to.be(true);
expect(suite.tags[0]).to.be("all");
});
});
it("default suites should be enabled by default", () => {
Suites.forEach((suite) => {
if (suite.tags.includes("default"))
expect(!suite.disabled);
});
});
it("should have 'default' and not 'experimental' tag", () => {
Suites.forEach((suite) => {
if (suite.tags.includes("experimental"))
expect(!suite.tags.includes("default"));
});
});
it("should not have duplicate tags", () => {
Suites.forEach((suite) => {
const uniqueTags = new Set(suite.tags);
expect(suite.tags).to.eql(Array.from(uniqueTags));
});
});
it("should have a name string", () => {
Suites.forEach((suite) => {
expect(suite.name).to.be.a("string");
expect(suite.name.length).to.be.greaterThan(0);
});
});
it("should have a url string", () => {
Suites.forEach((suite) => {
expect(suite.url).to.be.a("string");
expect(suite.url.length).to.be.greaterThan(0);
});
});
it("should have unique names", () => {
const uniqueNames = new Set();
Suites.forEach((suite) => {
expect(uniqueNames.has(suite.name)).to.be(false);
uniqueNames.add(suite.name);
});
});
});
Loading