Test backend with in-memory server in CI.
This commit is contained in:
parent
c4dd2dc6e3
commit
624aa34754
6 changed files with 199 additions and 41 deletions
30
packages/backend/scripts/testci.js
Normal file
30
packages/backend/scripts/testci.js
Normal file
|
@ -0,0 +1,30 @@
|
|||
/*
|
||||
* Starts an in-memory database and a server before running tests.
|
||||
*/
|
||||
|
||||
import '../tests/env.js';
|
||||
import mongoose from 'mongoose';
|
||||
import { MongoMemoryServer } from 'mongodb-memory-server';
|
||||
import { loadSampleData, runTasks } from '../src/cli/lib';
|
||||
import { startApp } from '../src/app';
|
||||
import { spawn } from 'child_process';
|
||||
|
||||
(async () => {
|
||||
return MongoMemoryServer.create({ instance: { port: 27017 } });
|
||||
})()
|
||||
.then((mongoServer) => {
|
||||
mongoose.connect(mongoServer.getUri() + "freesewing", { useNewUrlParser: true });
|
||||
})
|
||||
.then(() => { runTasks({ reboot: true }) })
|
||||
.then(loadSampleData)
|
||||
.then(startApp)
|
||||
.then(() => {
|
||||
// Forward command-line args to test process.
|
||||
const args = ['run', 'test', '--'].concat(process.argv.slice(2));
|
||||
spawn('npm', args, { stdio: 'inherit' })
|
||||
.on('exit', function(code) {
|
||||
// Propagate exit code so that test failures are recognized.
|
||||
process.exit(code);
|
||||
});
|
||||
});
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue