feat: add building of SNJS Docker image for e2e testing purposes (#1225)

* feat: add building of SNJS Docker image for e2e testing purposes

* fix: contents of snjs package

* feat: add running e2e test suite

* fix: include mocha directory in the snjs yarn package

* fix: add triggering e2e tests with specific image tag

* fix: mocha tests url

* fix: add tests before publishing new version

* fix: temporary skip linter errors

* Revert "fix: temporary skip linter errors"

This reverts commit c989536930a291677f6ef8cad402feb13f066b8c.

* fix: replace test libraries with unpkg CDN versions

* fix: update yarn lock and remove cached libs

* fix: add missing library to mocha tests

* fix: restore chai-as-promised built version

* fix: serving sncrypto-web in mocha test suite

* fix: add copy of sncrypto-web to gitignore files
This commit is contained in:
Karol Sójko
2022-07-08 11:36:12 +02:00
committed by GitHub
parent 0d16e6faaa
commit 3e4e7fd0e0
41 changed files with 256 additions and 468 deletions

1
packages/snjs/.gitignore vendored Normal file
View File

@@ -0,0 +1 @@
mocha/vendor/sncrypto-web.js

25
packages/snjs/Dockerfile Normal file
View File

@@ -0,0 +1,25 @@
FROM node:16.15.1-alpine AS builder
# Install dependencies for building native libraries
RUN apk add --update git openssh-client python3 alpine-sdk
WORKDIR /workspace
# docker-build plugin copies everything needed for `yarn install` to `manifests` folder.
COPY manifests ./
RUN yarn install --immutable
FROM node:16.15.1-alpine
RUN apk add --update curl
WORKDIR /workspace
# Copy the installed dependencies from the previous stage.
COPY --from=builder /workspace ./
# docker-build plugin runs `yarn pack` in all workspace dependencies and copies them to `packs` folder.
COPY packs ./
CMD [ "yarn", "start:test-server" ]

View File

@@ -0,0 +1,29 @@
/* Used for running mocha tests */
const connect = require('connect')
const serveStatic = require('serve-static')
const fs = require('fs')
const isDev = process.argv[2] === '--dev'
const port = isDev ? 9002 : 9001
const snCryptoDistFilePath = `${__dirname}/../sncrypto-web/dist/sncrypto-web.js`
if (!fs.existsSync(snCryptoDistFilePath)) {
console.error(
`Could not find sncrypto dist file under: ${snCryptoDistFilePath}. Please consider building the project first`,
)
process.exit(1)
}
fs.copyFileSync(snCryptoDistFilePath, `${__dirname}/mocha/vendor/sncrypto-web.js`)
connect()
.use(serveStatic(__dirname))
.listen(port, () => {
const url = `http://localhost:${port}/mocha/test.html`
console.log(`Test Server Started on ${url}`)
if (!isDev) {
const start = process.platform === 'darwin' ? 'open' : process.platform === 'win32' ? 'start' : 'xdg-open'
require('child_process').exec(start + ' ' + url)
}
})

View File

@@ -4,13 +4,13 @@
<meta charset="utf-8">
<title>Mocha Tests</title>
<link href="assets/mocha.css" rel="stylesheet" />
<script src="../../../.yarn/unplugged/chai-npm-4.3.6-dba90e4b0b/node_modules/chai/chai.js"></script>
<script src="https://unpkg.com/chai@4.3.6/chai.js"></script>
<script src="./vendor/chai-as-promised-built.js"></script>
<script src="../../../.yarn/unplugged/regenerator-runtime-npm-0.13.9-6d02340eec/node_modules/regenerator-runtime/runtime.js"></script>
<script src="../../../.yarn/unplugged/mocha-npm-9.2.2-f7735febb8/node_modules/mocha/mocha.js"></script>
<script src="../../../.yarn/unplugged/chai-subset-npm-1.6.0-3cee47a65d/node_modules/chai-subset/lib/chai-subset.js"></script>
<script src="../../sncrypto-web/dist//sncrypto-web.js"></script>
<script src="../../../.yarn/unplugged/sinon-npm-13.0.2-8544b59862/node_modules/sinon/pkg/sinon.js"></script>
<script src="https://unpkg.com/regenerator-runtime@0.13.9/runtime.js"></script>
<script src="https://unpkg.com/mocha@9.2.2/mocha.js"></script>
<script src="https://unpkg.com/chai-subset@1.6.0/lib/chai-subset.js"></script>
<script src="https://unpkg.com/sinon@13.0.2/pkg/sinon.js"></script>
<script src="./vendor/sncrypto-web.js"></script>
<script src="../dist/snjs.js"></script>
<script>
const urlParams = new URLSearchParams(window.location.search);

View File

@@ -8,12 +8,15 @@
"author": "Standard Notes",
"types": "dist/@types",
"files": [
"dist"
"dist",
"mocha",
"e2e-server.js"
],
"license": "AGPL-3.0-or-later",
"private": true,
"scripts": {
"start": "webpack -w --config webpack.dev.js",
"start:test-server": "yarn node e2e-server.js",
"clean": "rm -fr dist",
"prebuild": "yarn clean",
"build": "yarn tsc && webpack --config webpack.prod.js",
@@ -37,9 +40,6 @@
"@typescript-eslint/eslint-plugin": "^5.30.0",
"babel-jest": "^28.1.2",
"babel-loader": "^8.2.3",
"chai": "^4.3.6",
"chai-as-promised": "^7.1.1",
"chai-subset": "^1.6.0",
"circular-dependency-plugin": "^5.2.2",
"crypto-js": "^4.1.1",
"docdash": "^1.2.0",
@@ -52,13 +52,9 @@
"jsdom": "^19.0.0",
"libsodium-wrappers": "^0.7.9",
"lodash": "^4.17.21",
"mocha": "^9.2.1",
"mocha-headless-chrome": "^4.0.0",
"nock": "^13.2.4",
"otplib": "^12.0.1",
"regenerator-runtime": "^0.13.9",
"script-loader": "^0.7.2",
"sinon": "^13.0.1",
"ts-jest": "^28.0.5",
"ts-loader": "^9.2.6",
"ts-node": "^10.8.1",