Skip to content

Commit 97081ed

Browse files
authored
fix test script (disease-sh#986)
* fix test script * add scraper service * test mode * remove smart testing :( * remove smart testing :( * remove smart testing :( * remove smart testing :( * fix mocharc * vax scraper
1 parent cf896c7 commit 97081ed

File tree

7 files changed

+52
-63
lines changed

7 files changed

+52
-63
lines changed

.github/workflows/smart-test.yml

Lines changed: 35 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,35 @@
1-
name: Smart Unittest
2-
on:
3-
pull_request:
4-
branches:
5-
- '*'
6-
paths-ignore:
7-
- '.github/ISSUE_TEMPLATE/**'
8-
- 'docker-publish.yml'
9-
- 'README.md'
10-
- 'SECURITY.md'
11-
- 'TERMS.md'
12-
- 'privacy.md'
13-
- 'CONTRIBUTING.md'
14-
jobs:
15-
smart-unittest:
16-
runs-on: ubuntu-latest
17-
steps:
18-
- uses: actions/checkout@v2
19-
- uses: zcong1993/setup-timezone@master
20-
with:
21-
timezone: America/Denver
22-
# get changed files
23-
- id: files
24-
uses: jitterbit/get-changed-files@v1
25-
# create file to hold tests to run
26-
- run: touch test_to_run.txt
27-
# run node script mapping changed files to tests
28-
- run: node associateTests.js ${{ steps.files.outputs.all }} >> test_to_run.txt
29-
# supply this file as input to a testing script
30-
- run: npm run docker-test
31-
env:
32-
REDIS_HOST: localhost
33-
REDIS_PORT: 6379
34-
REDIS_PASSWORD: ""
35-
SERVER_PORT: 3000
1+
# name: Smart Unittest
2+
# on:
3+
# pull_request:
4+
# branches:
5+
# - '*'
6+
# paths-ignore:
7+
# - '.github/ISSUE_TEMPLATE/**'
8+
# - 'docker-publish.yml'
9+
# - 'README.md'
10+
# - 'SECURITY.md'
11+
# - 'TERMS.md'
12+
# - 'privacy.md'
13+
# - 'CONTRIBUTING.md'
14+
# jobs:
15+
# smart-unittest:
16+
# runs-on: ubuntu-latest
17+
# steps:
18+
# - uses: actions/checkout@v2
19+
# - uses: zcong1993/setup-timezone@master
20+
# with:
21+
# timezone: America/Denver
22+
# # get changed files
23+
# - id: files
24+
# uses: jitterbit/get-changed-files@v1
25+
# # create file to hold tests to run
26+
# - run: touch test_to_run.txt
27+
# # run node script mapping changed files to tests
28+
# - run: node associateTests.js ${{ steps.files.outputs.all }} >> test_to_run.txt
29+
# # supply this file as input to a testing script
30+
# - run: npm run docker-test
31+
# env:
32+
# REDIS_HOST: localhost
33+
# REDIS_PORT: 6379
34+
# REDIS_PASSWORD: ""
35+
# SERVER_PORT: 3000

.github/workflows/test.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ on:
1010
- 'TERMS.md'
1111
- 'privacy.md'
1212
- 'CONTRIBUTING.md'
13+
pull_request:
14+
branches:
15+
- '*'
1316
schedule:
1417
- cron: "0 */2 * * *"
1518
jobs:

docker-compose.test.yml

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,31 +2,16 @@ version: "3.7"
22

33
services:
44
redis:
5-
image: redis:5.0.8-buster
6-
hostname: redis
75
container_name: covid-api-redis-test
8-
networks:
9-
- redis-net
106
volumes:
117
- redis-data-test:/data
12-
138
app:
14-
image: novelcovid/novelcovid-api:latest
15-
command: /bin/sh -c "./runtests.sh"
16-
networks:
17-
- redis-net
18-
depends_on:
19-
- redis
20-
build:
21-
context: .
22-
dockerfile: Dockerfile-Test
9+
command: ["npm", "test"]
10+
build: .
2311
environment:
2412
- TEST_MODE=true
2513
- DOCKER=true
2614
container_name: covid-api-app-test
2715

28-
networks:
29-
redis-net:
30-
3116
volumes:
3217
redis-data-test:

docker-compose.yml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@ services:
1212

1313
app:
1414
image: novelcovid/novelcovid-api:latest
15-
environment:
16-
- DOCKER=true
1715
networks:
1816
- redis-net
1917
depends_on:
@@ -23,4 +21,4 @@ networks:
2321
redis-net:
2422

2523
volumes:
26-
redis-data:
24+
redis-data:

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
"docker-down": "docker-compose -f docker-compose.yml -f docker-compose.prod.yml down --rmi all",
2828
"docker-start-dev": "docker-compose -f docker-compose.yml -f docker-compose.dev.yml up -d --build",
2929
"docker-down-dev": "docker-compose -f docker-compose.yml -f docker-compose.dev.yml down --rmi all",
30-
"docker-test": "docker-compose -f docker-compose.test.yml up --abort-on-container-exit --build"
30+
"docker-test": "docker-compose -f docker-compose.yml -f docker-compose.test.yml up --abort-on-container-exit --build"
3131
},
3232
"dependencies": {
3333
"@sentry/node": "5.12.2",

runtests.sh

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,6 @@
1-
npm run test-single $(cat test_to_run.txt | while read line; do echo $line; done)
1+
if [ -s test_to_run.txt ]
2+
then
3+
npm run test
4+
else
5+
npm run test-single $(cat test_to_run.txt | while read line; do echo $line; done)
6+
fi

tests/mochaSetup.spec.js

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ const { scraper: { executeScraper, executeScraperNYTData, excecuteScraperAppleDa
22
redis } = require('../routes/instances');
33
const logger = require('../utils/logger');
44

5-
const testFileArgs = process.argv.splice(5);
6-
const argValues = new Set(testFileArgs.map(fl => fl.substring(fl.indexOf('_') + 1, fl.indexOf('.'))));
5+
const [arg] = process.argv[5].split('/').slice(-1);
6+
const argValue = arg.substring(arg.indexOf('_') + 1, arg.indexOf('.'));
77
const mapArgToScraper = {
88
worldometers: executeScraper,
99
jhucsse: executeScraper,
@@ -19,10 +19,8 @@ const mapArgToScraper = {
1919
before(async () => {
2020
await redis.flushall();
2121
logger.info('Finished flushing all data from redis.');
22-
if (argValues) {
23-
await Promise.all(Array.from(argValues).map(async (argValue) => {
24-
if (mapArgToScraper[argValue]) await mapArgToScraper[argValue]();
25-
}));
22+
if (argValue in mapArgToScraper) {
23+
await mapArgToScraper[argValue]();
2624
} else {
2725
await executeScraper();
2826
await executeScraperNYTData();

0 commit comments

Comments
 (0)