From 86e6c9709ef2718537187353dc4838502640c0bb Mon Sep 17 00:00:00 2001 From: deanchen Date: Thu, 17 Jun 2021 10:22:05 +0800 Subject: [PATCH] feat: e2e can run locally --- README.md | 20 ++++++++++++++++++++ __tests__/e2e/config.js | 8 ++++++-- __tests__/e2e/database/knex.js | 3 ++- package.json | 1 + 4 files changed, 29 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 48385809..34e57776 100644 --- a/README.md +++ b/README.md @@ -439,6 +439,26 @@ In order to efficiently run our integration tests, we rely on automated database npm run test-seedDB ``` +## End to End test + +To run the test: + +``` +npm run test-e2e +``` + +To run the test locally against the local code/server: + +``` +npm run test-e2e-locally +``` + +NOTE running e2e needs to set up some env variables like the Database connection, we can attach the env variables on the CLI command line: + +``` +> DB_HOST=localhost DB_USERNAME=postgres DB_PORT=23720 DB_PASSWORD=*** DB_NAME=treetracker DB_SCHEMA=public npm run test-e2e-locally +``` + ## Suggestion about how to run tests when developing There is a command in the `package.json`: diff --git a/__tests__/e2e/config.js b/__tests__/e2e/config.js index 674ba5d8..3383a051 100644 --- a/__tests__/e2e/config.js +++ b/__tests__/e2e/config.js @@ -1,6 +1,10 @@ require("dotenv").config(); -const request = require("supertest")(`https://${process.env.ENVIRONMENT}-k8s.treetracker.org/wallet`); +const server = process.env.RUN_E2E_LOCALLY ? + require("../../server/app") + : + `https://${process.env.ENVIRONMENT}-k8s.treetracker.org/wallet`; +const request = require("supertest")(server); const expect = require("chai").expect; const responseStatus = require("http-status-codes"); const assert = require("./libs/assertionLibrary.js"); @@ -27,4 +31,4 @@ module.exports = { responseStatus, assert, seed -}; \ No newline at end of file +}; diff --git a/__tests__/e2e/database/knex.js b/__tests__/e2e/database/knex.js index 706d2907..10155830 100644 --- a/__tests__/e2e/database/knex.js +++ b/__tests__/e2e/database/knex.js @@ -8,7 +8,8 @@ const knexConfig = { port: process.env.DB_PORT, password: process.env.DB_PASSWORD, database: process.env.DB_NAME, - ssl: true, + // eslint-disable-next-line + ssl: process.env.DB_SSL === "false" ? false : true, }, debug: false, searchPath: [process.env.DB_SCHEMA], diff --git a/package.json b/package.json index 1953c372..535da92c 100644 --- a/package.json +++ b/package.json @@ -22,6 +22,7 @@ "test-watch": "NODE_ENV=test NODE_LOG_LEVEL=info mocha -r dotenv/config dotenv_config_path=.env.test --timeout 10000 --require co-mocha -w -b --ignore './server/repositories/**/*.spec.js' './server/setup.js' './server/**/*.spec.js' './__tests__/seed.spec.js' './__tests__/supertest.js'", "test-watch-debug": "NODE_ENV=test NODE_LOG_LEVEL=debug DOTENV_CONFIG_PATH=.env.test mocha -r dotenv/config --timeout 10000 --require co-mocha -w -b --ignore './server/repositories/**/*.spec.js' './server/setup.js' './server/**/*.spec.js' './__tests__/seed.spec.js' './__tests__/**/*.spec.js'", "test-e2e": "NODE_TLS_REJECT_UNAUTHORIZED='0' mocha --config ./__tests__/e2e/.mocharc.js", + "test-e2e-locally": "RUN_E2E_LOCALLY=true DB_SSL=false NODE_ENV=test NODE_LOG_LEVEL=debug NODE_TLS_REJECT_UNAUTHORIZED='0' mocha --config ./__tests__/e2e/.mocharc.js ./server/setup.js", "prettier-fix": "prettier ./ --write", "db-migrate-ci": "cd database; db-migrate up", "start-db": "docker-compose up"