Web Dev Solutions

Catalin Mititiuc

aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCatalin Mititiuc <webdevcat@proton.me>2024-04-17 15:56:41 -0700
committerCatalin Mititiuc <webdevcat@proton.me>2024-04-17 15:56:41 -0700
commit24e2bd5821b09d4d7e243fc62ab36f45454a0a03 (patch)
tree464830f06896e3725da889159ae6296781071c7f
parent143e3cdb45a96912d6791a37f64bf3893879cd93 (diff)
Add beginning setup for tests
-rw-r--r--Dockerfile31
-rw-r--r--README.md10
-rw-r--r--google_test.js22
-rw-r--r--package-lock.json146
-rw-r--r--package.json4
5 files changed, 211 insertions, 2 deletions
diff --git a/Dockerfile b/Dockerfile
new file mode 100644
index 0000000..77e51ff
--- /dev/null
+++ b/Dockerfile
@@ -0,0 +1,31 @@
+FROM node
+
+RUN apt-get update -qq -y && \
+ apt-get install -y \
+ libasound2 \
+ libatk-bridge2.0-0 \
+ libgtk-4-1 \
+ libnss3 \
+ xdg-utils \
+ wget && \
+ wget -q -O chrome-linux64.zip https://storage.googleapis.com/chrome-for-testing-public/123.0.6312.122/linux64/chrome-linux64.zip && \
+ unzip chrome-linux64.zip && \
+ rm chrome-linux64.zip && \
+ mv chrome-linux64 /opt/chrome/ && \
+ ln -s /opt/chrome/chrome /usr/local/bin/ && \
+ wget -q -O chromedriver-linux64.zip https://storage.googleapis.com/chrome-for-testing-public/123.0.6312.122/linux64/chromedriver-linux64.zip && \
+ unzip -j chromedriver-linux64.zip chromedriver-linux64/chromedriver && \
+ rm chromedriver-linux64.zip && \
+ mv chromedriver /usr/local/bin/
+
+WORKDIR /usr/src/app
+COPY package*.json .
+
+ENV CHROMEDRIVER_SKIP_DOWNLOAD=true
+
+RUN npm install --omit=dev
+RUN npm install chromedriver
+
+COPY . .
+
+CMD [ "npm", "start" ]
diff --git a/README.md b/README.md
index f6682a1..394ed06 100644
--- a/README.md
+++ b/README.md
@@ -8,6 +8,16 @@
Visit `localhost:8080` to view.
+## Run a test
+
+You need chrome and chromedriver installed. The Dockerfile builds an image that does that. Then run the test with that image.
+
+`--network host` gives the container internet access. Necessary if tests make outside requests.
+
+ docker run --rm -it -v $PWD:/usr/src/app --network host btroops node google_test
+
+TODO add firefox and geckodriver
+
## Rough way to save the SVG map generated by JavaScript client-side
const XMLS = new XMLSerializer();
diff --git a/google_test.js b/google_test.js
new file mode 100644
index 0000000..bf751a6
--- /dev/null
+++ b/google_test.js
@@ -0,0 +1,22 @@
+import { Builder } from 'selenium-webdriver';
+import chrome from 'selenium-webdriver/chrome.js';
+
+console.log("Start the browser.")
+
+let chromeOptions = new chrome.Options();
+chromeOptions.addArguments('--headless', '--disable-gpu', '--no-sandbox');
+
+let driver = new Builder()
+ .forBrowser('chrome')
+ .setChromeOptions(chromeOptions)
+ .build();
+
+console.log("Done!")
+
+console.log("Open Google.")
+await driver.get("https://google.com");
+console.log("Done!")
+
+const html = await driver.getPageSource();
+
+driver.quit()
diff --git a/package-lock.json b/package-lock.json
index 176a8c6..a16e628 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -9,7 +9,8 @@
},
"devDependencies": {
"esbuild": "^0.20.2",
- "esbuild-server": "^0.3.0"
+ "esbuild-server": "^0.3.0",
+ "selenium-webdriver": "^4.19.0"
}
},
"node_modules/@esbuild/linux-x64": {
@@ -27,6 +28,12 @@
"node": ">=12"
}
},
+ "node_modules/core-util-is": {
+ "version": "1.0.3",
+ "resolved": "https://registry.npmjs.org/core-util-is/-/core-util-is-1.0.3.tgz",
+ "integrity": "sha512-ZQBvi1DcpJ4GDqanjucZ2Hj3wEO5pZDS89BWbkcrvdxksJorwUDDZamX9ldFkp9aw2lmBDLgkObEA4DWNJ9FYQ==",
+ "dev": true
+ },
"node_modules/esbuild": {
"version": "0.20.2",
"dev": true,
@@ -75,8 +82,145 @@
"esbuild": ">=0.17.0"
}
},
+ "node_modules/immediate": {
+ "version": "3.0.6",
+ "resolved": "https://registry.npmjs.org/immediate/-/immediate-3.0.6.tgz",
+ "integrity": "sha512-XXOFtyqDjNDAQxVfYxuF7g9Il/IbWmmlQg2MYKOH8ExIT1qg6xc4zyS3HaEEATgs1btfzxq15ciUiY7gjSXRGQ==",
+ "dev": true
+ },
+ "node_modules/inherits": {
+ "version": "2.0.4",
+ "resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.4.tgz",
+ "integrity": "sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ==",
+ "dev": true
+ },
+ "node_modules/isarray": {
+ "version": "1.0.0",
+ "resolved": "https://registry.npmjs.org/isarray/-/isarray-1.0.0.tgz",
+ "integrity": "sha512-VLghIWNM6ELQzo7zwmcg0NmTVyWKYjvIeM83yjp0wRDTmUnrM678fQbcKBo6n2CJEF0szoG//ytg+TKla89ALQ==",
+ "dev": true
+ },
+ "node_modules/jszip": {
+ "version": "3.10.1",
+ "resolved": "https://registry.npmjs.org/jszip/-/jszip-3.10.1.tgz",
+ "integrity": "sha512-xXDvecyTpGLrqFrvkrUSoxxfJI5AH7U8zxxtVclpsUtMCq4JQ290LY8AW5c7Ggnr/Y/oK+bQMbqK2qmtk3pN4g==",
+ "dev": true,
+ "dependencies": {
+ "lie": "~3.3.0",
+ "pako": "~1.0.2",
+ "readable-stream": "~2.3.6",
+ "setimmediate": "^1.0.5"
+ }
+ },
+ "node_modules/lie": {
+ "version": "3.3.0",
+ "resolved": "https://registry.npmjs.org/lie/-/lie-3.3.0.tgz",
+ "integrity": "sha512-UaiMJzeWRlEujzAuw5LokY1L5ecNQYZKfmyZ9L7wDHb/p5etKaxXhohBcrw0EYby+G/NA52vRSN4N39dxHAIwQ==",
+ "dev": true,
+ "dependencies": {
+ "immediate": "~3.0.5"
+ }
+ },
+ "node_modules/pako": {
+ "version": "1.0.11",
+ "resolved": "https://registry.npmjs.org/pako/-/pako-1.0.11.tgz",
+ "integrity": "sha512-4hLB8Py4zZce5s4yd9XzopqwVv/yGNhV1Bl8NTmCq1763HeK2+EwVTv+leGeL13Dnh2wfbqowVPXCIO0z4taYw==",
+ "dev": true
+ },
+ "node_modules/process-nextick-args": {
+ "version": "2.0.1",
+ "resolved": "https://registry.npmjs.org/process-nextick-args/-/process-nextick-args-2.0.1.tgz",
+ "integrity": "sha512-3ouUOpQhtgrbOa17J7+uxOTpITYWaGP7/AhoR3+A+/1e9skrzelGi/dXzEYyvbxubEF6Wn2ypscTKiKJFFn1ag==",
+ "dev": true
+ },
+ "node_modules/readable-stream": {
+ "version": "2.3.8",
+ "resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-2.3.8.tgz",
+ "integrity": "sha512-8p0AUk4XODgIewSi0l8Epjs+EVnWiK7NoDIEGU0HhE7+ZyY8D1IMY7odu5lRrFXGg71L15KG8QrPmum45RTtdA==",
+ "dev": true,
+ "dependencies": {
+ "core-util-is": "~1.0.0",
+ "inherits": "~2.0.3",
+ "isarray": "~1.0.0",
+ "process-nextick-args": "~2.0.0",
+ "safe-buffer": "~5.1.1",
+ "string_decoder": "~1.1.1",
+ "util-deprecate": "~1.0.1"
+ }
+ },
+ "node_modules/safe-buffer": {
+ "version": "5.1.2",
+ "resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.1.2.tgz",
+ "integrity": "sha512-Gd2UZBJDkXlY7GbJxfsE8/nvKkUEU1G38c1siN6QP6a9PT9MmHB8GnpscSmMJSoF8LOIrt8ud/wPtojys4G6+g==",
+ "dev": true
+ },
+ "node_modules/selenium-webdriver": {
+ "version": "4.19.0",
+ "resolved": "https://registry.npmjs.org/selenium-webdriver/-/selenium-webdriver-4.19.0.tgz",
+ "integrity": "sha512-8XHW8m9V2XN2/SC1kr4bWzMtGvjmKUEZ6S0UBoDBqonhmwEIzKOLbzhanBd08HCOg1s1O0XrDWCD71NnA8Zt0g==",
+ "dev": true,
+ "dependencies": {
+ "jszip": "^3.10.1",
+ "tmp": "^0.2.3",
+ "ws": ">=8.16.0"
+ },
+ "engines": {
+ "node": ">= 14.20.0"
+ }
+ },
+ "node_modules/setimmediate": {
+ "version": "1.0.5",
+ "resolved": "https://registry.npmjs.org/setimmediate/-/setimmediate-1.0.5.tgz",
+ "integrity": "sha512-MATJdZp8sLqDl/68LfQmbP8zKPLQNV6BIZoIgrscFDQ+RsvK/BxeDQOgyxKKoh0y/8h3BqVFnCqQ/gd+reiIXA==",
+ "dev": true
+ },
+ "node_modules/string_decoder": {
+ "version": "1.1.1",
+ "resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-1.1.1.tgz",
+ "integrity": "sha512-n/ShnvDi6FHbbVfviro+WojiFzv+s8MPMHBczVePfUpDJLwoLT0ht1l4YwBCbi8pJAveEEdnkHyPyTP/mzRfwg==",
+ "dev": true,
+ "dependencies": {
+ "safe-buffer": "~5.1.0"
+ }
+ },
"node_modules/svg-pan-zoom": {
"resolved": "git+ssh://git@github.com/webdevcat-me/svg-pan-zoom.git#8ea4e018b475eac05eb7ae8a067850c9bef7c2b5"
+ },
+ "node_modules/tmp": {
+ "version": "0.2.3",
+ "resolved": "https://registry.npmjs.org/tmp/-/tmp-0.2.3.tgz",
+ "integrity": "sha512-nZD7m9iCPC5g0pYmcaxogYKggSfLsdxl8of3Q/oIbqCqLLIO9IAF0GWjX1z9NZRHPiXv8Wex4yDCaZsgEw0Y8w==",
+ "dev": true,
+ "engines": {
+ "node": ">=14.14"
+ }
+ },
+ "node_modules/util-deprecate": {
+ "version": "1.0.2",
+ "resolved": "https://registry.npmjs.org/util-deprecate/-/util-deprecate-1.0.2.tgz",
+ "integrity": "sha512-EPD5q1uXyFxJpCrLnCc1nHnq3gOa6DZBocAIiI2TaSCA7VCJ1UJDMagCzIkXNsUYfD1daK//LTEQ8xiIbrHtcw==",
+ "dev": true
+ },
+ "node_modules/ws": {
+ "version": "8.16.0",
+ "resolved": "https://registry.npmjs.org/ws/-/ws-8.16.0.tgz",
+ "integrity": "sha512-HS0c//TP7Ina87TfiPUz1rQzMhHrl/SG2guqRcTOIUYD2q8uhUdNHZYJUaQ8aTGPzCh+c6oawMKW35nFl1dxyQ==",
+ "dev": true,
+ "engines": {
+ "node": ">=10.0.0"
+ },
+ "peerDependencies": {
+ "bufferutil": "^4.0.1",
+ "utf-8-validate": ">=5.0.2"
+ },
+ "peerDependenciesMeta": {
+ "bufferutil": {
+ "optional": true
+ },
+ "utf-8-validate": {
+ "optional": true
+ }
+ }
}
}
}
diff --git a/package.json b/package.json
index 54db50a..1f55bdb 100644
--- a/package.json
+++ b/package.json
@@ -1,7 +1,9 @@
{
+ "type": "module",
"devDependencies": {
"esbuild": "^0.20.2",
- "esbuild-server": "^0.3.0"
+ "esbuild-server": "^0.3.0",
+ "selenium-webdriver": "^4.19.0"
},
"dependencies": {
"svg-pan-zoom": "github:webdevcat-me/svg-pan-zoom"