Skip to content

Commit

Permalink
added unit test framework and unit test github action
Browse files Browse the repository at this point in the history
  • Loading branch information
crpietschmann committed Mar 13, 2024
1 parent d74ad2d commit a7ab985
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 2 deletions.
33 changes: 33 additions & 0 deletions .github/workflows/test-app-nodejs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
name: Test App - Node.js

on:
push:
paths:
- 'app/**'
pull_request:
paths:
- 'app/**'
workflow_dispatch:

jobs:
test-app:
name: 'Test Node.js App'
runs-on: ubuntu-latest

defaults:
run:
shell: bash
working-directory: 'app'

steps:
- name: Checkout
uses: actions/checkout@v4

- name: Setup Node.js
uses: actions/setup-node@v4

- name: NPM Install
run: npm install

- name: NPM Test
run: npm test
4 changes: 2 additions & 2 deletions app/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,6 @@ require('./api/v2.js')(app)
swagger(app)

const port = process.env.PORT || 8080;
app.listen(port, () => {
module.exports = app.listen(port, () => {
console.log(`Server running on port ${port}`);
});
});
6 changes: 6 additions & 0 deletions app/package.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
{
"dependencies": {
"@azure/openai": "^1.0.0-beta.11",
"chai": "^4.4.1",
"chai-http": "^4.4.0",
"cors": "^2.8.5",
"dotenv": "^16.4.5",
"express": "^4.18.3",
"mocha": "^10.3.0",
"swagger-jsdoc": "^6.2.8",
"swagger-ui-express": "^5.0.0"
},
"scripts": {
"test": "mocha test/*.js --exit"
}
}
18 changes: 18 additions & 0 deletions app/test/test-webapp.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
const chai = require('chai'),
expect = chai.expect,
chaiHttp = require('chai-http')

chai.use(chaiHttp)

const app = require('../app.js')

describe('AIChatUI Web App', function() {
it('should respond with a 200 status code', function(done) {
chai.request(app)
.get('/')
.end(function(err, res) {
expect(res).to.have.status(200);
done();
});
});
});
8 changes: 8 additions & 0 deletions app/test/test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
const assert = require('assert')
describe('Array', function () {
describe('#indexOf()', function () {
it('should return -1 when the value is not present', function () {
assert.equal([1, 2, 3].indexOf(4), -1);
});
});
});

0 comments on commit a7ab985

Please sign in to comment.