Skip to content
This repository has been archived by the owner on Sep 27, 2022. It is now read-only.

Commit

Permalink
refactor(test): Allow tests to run in parallel
Browse files Browse the repository at this point in the history
  • Loading branch information
anishkny committed Dec 9, 2017
1 parent 6dc97cb commit f8f226f
Show file tree
Hide file tree
Showing 8 changed files with 46 additions and 6 deletions.
2 changes: 1 addition & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ module.exports = {
'prefer-const': 'error',
'semi': 'error',
'space-before-function-paren': ['error', {
'anonymous': 'always',
'anonymous': 'never',
'asyncArrow': 'always',
'named': 'never',
}],
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
node_modules
dist
package-lock.json
yarn.lock
service-account-key.json
.nyc_output
coverage
Expand Down
33 changes: 32 additions & 1 deletion api-tests.postman.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"info": {
"name": "Realworld API",
"_postman_id": "8f613b45-6d18-3b58-f9de-2ee4b83f543d",
"_postman_id": "3e226695-958b-be2d-4262-c41cdf635a21",
"description": "",
"schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json"
},
Expand Down Expand Up @@ -1387,6 +1387,37 @@
}
},
"response": []
},
{
"name": "Clean Slate",
"event": [{
"listen": "test",
"script": {
"type": "text/javascript",
"exec": [
"tests['should have status 200'] = pm.response.code === 200;",
""
]
}
}],
"request": {
"method": "PURGE",
"header": [],
"body": {
"mode": "raw",
"raw": ""
},
"url": {
"raw": "{{apiUrl}}/__DELETE_ALL_DATA__",
"host": [
"{{apiUrl}}"
],
"path": [
"__DELETE_ALL_DATA__"
]
}
},
"response": []
}
]
}
2 changes: 1 addition & 1 deletion deploy-to-cloud.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ rm -rf dist/
babel index.js src/*.js --presets es2015,stage-3 --out-dir dist/ --ignore *.test.js

## Setup dist folder with additional files
echo DATASTORE_NAMESPACE=test-api-cloud > dist/.env
echo DATASTORE_NAMESPACE=test-api-cloud-`date +%s` > dist/.env
cp package.json dist/

## Deploy to Cloud Functions
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"scripts": {
"test": "npm run lint && npm run test:unit && npm run test:api",
"lint": "eslint index.js src/",
"test:unit": "DATASTORE_NAMESPACE=test-unit nyc mocha --opts .mochaopts ./src/*.test.js",
"test:unit": "DATASTORE_NAMESPACE=test-unit-`date +%s` nyc mocha --opts .mochaopts ./src/*.test.js",
"test:api": "./run-api-tests.sh",
"deploy": "./deploy-to-cloud.sh"
},
Expand Down
2 changes: 1 addition & 1 deletion run-api-tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ echo PWD=`pwd`

## Deploy to Cloud Functions Local Emulator
echo "Using functions emulator located at: ["`which functions`"]"
export DATASTORE_NAMESPACE=test-api
export DATASTORE_NAMESPACE=test-api-`date +%s`
echo $GCP_PROJECT_ID | functions start > /dev/null
if [ -n "$CI" ]; then
functions config set watch false
Expand Down
4 changes: 4 additions & 0 deletions src/Article.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ describe('Article module', async () => {
});
});

after(async () => {
await cleanSlate();
});

it('should create new article', async () => {
createdArticle = await Article.create({
title: casual.title,
Expand Down
6 changes: 5 additions & 1 deletion src/User.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ describe('User module', async () => {
await cleanSlate();
});

after(async () => {
await cleanSlate();
});

it('should create new user', async () => {
const createdUser = await User.create(userToCreate);
mlog.log(`Created user: [${JSON.stringify(createdUser)}]`);
Expand Down Expand Up @@ -143,7 +147,7 @@ describe('User module', async () => {
});

function delay(time) {
return new Promise(function (fulfill) {
return new Promise(function(fulfill) {
setTimeout(fulfill, time);
});
}
Expand Down

0 comments on commit f8f226f

Please sign in to comment.