Skip to content

Commit

Permalink
feat: e2e can run locally
Browse files Browse the repository at this point in the history
  • Loading branch information
dadiorchen committed Jun 17, 2021
1 parent cce83de commit 86e6c97
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 3 deletions.
20 changes: 20 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`:
Expand Down
8 changes: 6 additions & 2 deletions __tests__/e2e/config.js
Original file line number Diff line number Diff line change
@@ -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");
Expand All @@ -27,4 +31,4 @@ module.exports = {
responseStatus,
assert,
seed
};
};
3 changes: 2 additions & 1 deletion __tests__/e2e/database/knex.js
Original file line number Diff line number Diff line change
Expand Up @@ -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],
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit 86e6c97

Please sign in to comment.