Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add a "test" mode #30

Closed
wants to merge 8 commits into from
Closed
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ FROM node:14.16.1-alpine

LABEL maintainer="[email protected]"

RUN apk update && apk upgrade && apk add --no-cache bash git openssh
RUN apk update && apk upgrade && apk add --no-cache bash git jq
nvdk marked this conversation as resolved.
Show resolved Hide resolved

ENV MU_SPARQL_ENDPOINT 'http://database:8890/sparql'
ENV MU_APPLICATION_GRAPH 'http://mu.semte.ch/application'
Expand Down
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -177,3 +177,16 @@ When running inside a mu.semte.ch stack, you could mount your sources and connec
- /absolute/path/to/your/sources/:/app/
```
Now open Chromium, and visit [chrome://inspect/](chrome://inspect/). Once the service is launched, a remote target on localhost should pop up.

## Running tests [BETA]
The javascript template provides [mocha](https://mochajs.org/#getting-started) as a testing framework. Create a `test` folder in your application root and nest any tests under that folder.
You can run tests by setting the `NODE_ENV` to "test":

```bash
docker run
--rm
-v `pwd`:/app \
-e NODE_ENV=test \
--name my-js-test \
semtech/mu-javascript-template
```
5 changes: 4 additions & 1 deletion boot.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,11 @@ then
# Run live-reload development
exec /usr/src/app/node_modules/.bin/nodemon \
--watch /app \
--ext js,mjs,cjs,json \
--ext js,mjs,cjs,json,hbs \
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not really related to this PR, but reload on changed hbs files is appreciated

--exec /usr/src/app/run-development.sh
elif [ "$NODE_ENV" == "test" ]
then
exec /usr/src/app/run-test.sh
elif [ "$NODE_ENV" == "production" ]
then
diff -rq /app /app.original > /dev/null
Expand Down
5 changes: 5 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
"type": "git",
"url": "git+https://github.com/mu-semtech/mu-javascript-template.git"
},
"scripts": {
"test": "mocha --require @babel/register"
},
"keywords": [
"mu-semtech"
],
Expand All @@ -16,11 +19,13 @@
"@babel/plugin-proposal-class-properties": "^7.13.0",
"@babel/plugin-proposal-decorators": "^7.13.15",
"@babel/preset-env": "^7.14.1",
"@babel/register": "^7.13.16",
"babel-plugin-module-resolver": "4.1.0",
"body-parser": "~1.19.0",
"env-var": "^7.0.0",
"express": "^4.17.1",
"express-http-context": "~1.2.4",
"mocha": "^8.4.0",
"nodemon": "^2.0.7",
"sparql-client-2": "https://github.com/erikap/node-sparql-client.git",
"uuid": "^8.3.2"
Expand Down
14 changes: 14 additions & 0 deletions run-test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/bin/sh

# create a copy of app, so we can modify as necessary
cp -a /app /usr/src/out

# add some required files from the template
cp -a /usr/src/app/.babelrc.js /usr/src/app/helpers /usr/src/out/
# merge package.json files, prefering whatever is specified in the app
jq -s '.[0] * .[1]' /usr/src/app/package.json /app/package.json > /usr/src/out/package.json
Copy link
Member Author

@nvdk nvdk May 27, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

-s is for slurp, which means read the entire thing before applying the operation
* is the multiplier operation, documented as:

Multiplying two objects will merge them recursively: this works like addition but if both objects contain a value for the same key, and the values are objects, the two are merged with the same strategy.

more info on https://stedolan.github.io/jq/manual/#Builtinoperatorsandfunctions


# do things
cd /usr/src/out
npm install
npm test