From dd7d876f29bcaa6e9a77d8e2a74ac50f78f5f4ee Mon Sep 17 00:00:00 2001 From: Arthur Lu Date: Wed, 16 Nov 2022 16:10:31 -0800 Subject: [PATCH] add dependencies to package.json, add http-server script to package.json, add simple e2e test in main.e2e.test.js Signed-off-by: Arthur Lu --- package.json | 7 +++-- source/assets/scripts/localStorage.test.js | 9 ++++--- source/assets/scripts/main.e2e.test.js | 31 ++++++++++++++++++++++ 3 files changed, 41 insertions(+), 6 deletions(-) create mode 100644 source/assets/scripts/main.e2e.test.js diff --git a/package.json b/package.json index bd8a69c..9d0267d 100644 --- a/package.json +++ b/package.json @@ -7,7 +7,8 @@ "lint": "eslint '**/*.js'", "fix-style": "eslint --fix **/*.js", "lintHTML": "htmlhint '**/*.html'", - "lintCSS": "stylelint '**/*.css'" + "lintCSS": "stylelint '**/*.css'", + "http-server": "http-server source &" }, "devDependencies": { "eslint": "^8.27.0", @@ -15,6 +16,8 @@ "mocha": "10", "mock-local-storage": "^1.1.23", "stylelint": "14.14.1", - "stylelint-config-standard": "^29.0.0" + "stylelint-config-standard": "^29.0.0", + "puppeteer": "18", + "http-server": "" } } diff --git a/source/assets/scripts/localStorage.test.js b/source/assets/scripts/localStorage.test.js index 65574b8..90ed2b7 100644 --- a/source/assets/scripts/localStorage.test.js +++ b/source/assets/scripts/localStorage.test.js @@ -2,11 +2,12 @@ import {strict as assert} from "node:assert"; import {describe, it, beforeEach} from "mocha"; import {saveReviewsToStorage, getReviewsFromStorage} from "./localStorage.js"; -beforeEach(() => { - localStorage.clear(); -}); - describe("test app localStorage interaction", () => { + + beforeEach(() => { + localStorage.clear(); + }); + it("get after init", () => { assert.deepEqual(getReviewsFromStorage(), []); }); diff --git a/source/assets/scripts/main.e2e.test.js b/source/assets/scripts/main.e2e.test.js new file mode 100644 index 0000000..2a61fc5 --- /dev/null +++ b/source/assets/scripts/main.e2e.test.js @@ -0,0 +1,31 @@ +import {strict as assert} from "node:assert"; +import {describe, it, beforeEach} from "mocha"; +import puppeteer from 'puppeteer-core'; +import { exit } from "node:process"; + +describe("test App end to end", async () => { + + let browser; + let page; + + beforeEach(async () => { + browser = await puppeteer.launch(); + page = await browser.newPage(); + try{ + await page.goto('http://localhost:8080', {timeout: 1000}); + } + catch (error) { + console.log("❌ failed to connect to localhost webserver on port 8080") + exit(1); + } + }); + + it("page should have correct title", async () => { + assert.strictEqual(await page.title(), "Food Journal"); + }); + + afterEach(async () => { + await page.close(); + await browser.close(); + }); +}); \ No newline at end of file