mirror of
https://github.com/leon-ai/leon.git
synced 2024-08-17 06:00:33 +03:00
chore: use different modules DBs while testing and flush them at the end of the tests
This commit is contained in:
parent
0f02e5b9dc
commit
81ec213ff2
@ -18,7 +18,6 @@ dirname = path.dirname(path.realpath(__file__))
|
||||
queryobjectpath = argv[1]
|
||||
codes = []
|
||||
|
||||
serversrc = 'dist' if environ.get('LEON_NODE_ENV') == 'production' else 'src'
|
||||
queryobjfile = open(queryobjectpath, 'r', encoding = 'utf8')
|
||||
queryobj = loads(queryobjfile.read())
|
||||
queryobjfile.close()
|
||||
|
@ -23,10 +23,10 @@
|
||||
"scripts": {
|
||||
"lint": "babel-node scripts/lint.js",
|
||||
"test": "npm run test:json && npm run test:unit && npm run test:e2e",
|
||||
"test:unit": "npm run train expressions:en && cross-env PIPENV_PIPFILE=bridges/python/Pipfile jest --forceExit --silent --projects test/unit/unit.jest.json && npm run train expressions",
|
||||
"test:unit": "npm run train expressions:en && cross-env PIPENV_PIPFILE=bridges/python/Pipfile LEON_NODE_ENV=testing jest --forceExit --silent --projects test/unit/unit.jest.json && npm run train expressions",
|
||||
"test:e2e": "npm run test:e2e:nlp-modules && npm run test:e2e:modules",
|
||||
"test:e2e:modules": "npm run train expressions:en && cross-env PIPENV_PIPFILE=bridges/python/Pipfile jest --forceExit --silent --verbose --projects test/e2e/modules/e2e.modules.jest.json && npm run train expressions",
|
||||
"test:e2e:nlp-modules": "npm run train expressions:en && cross-env PIPENV_PIPFILE=bridges/python/Pipfile jest --forceExit --silent --verbose --setupTestFrameworkScriptFile=./test/paths.setup.js test/e2e/nlp-modules.spec.js && npm run train expressions",
|
||||
"test:e2e:modules": "npm run train expressions:en && cross-env PIPENV_PIPFILE=bridges/python/Pipfile LEON_NODE_ENV=testing jest --forceExit --silent --verbose --projects test/e2e/modules/e2e.modules.jest.json && babel-node scripts/run-clean-test-dbs.js && npm run train expressions",
|
||||
"test:e2e:nlp-modules": "npm run train expressions:en && cross-env PIPENV_PIPFILE=bridges/python/Pipfile LEON_NODE_ENV=testing jest --forceExit --silent --verbose --setupTestFrameworkScriptFile=./test/paths.setup.js test/e2e/nlp-modules.spec.js && npm run train expressions",
|
||||
"test:json": "jest --silent --projects test/json/json.jest.json",
|
||||
"test:module": "babel-node scripts/test-module.js",
|
||||
"setup:offline": "babel-node scripts/setup-offline/setup-offline.js",
|
||||
|
@ -1,17 +1,4 @@
|
||||
import path from 'path'
|
||||
import fs from 'fs'
|
||||
|
||||
describe('calendar:todolist', async () => {
|
||||
// Once the tests are done, delete test DB file if it exists
|
||||
afterAll(() => {
|
||||
const pkgName = 'calendar'
|
||||
const dbFile = path.join(__dirname, `../data/db/${pkgName}.spec.json`)
|
||||
|
||||
if (fs.existsSync(dbFile)) {
|
||||
fs.unlinkSync(dbFile)
|
||||
}
|
||||
})
|
||||
|
||||
test('no list', async () => {
|
||||
global.nlu.brain.execute = jest.fn()
|
||||
await global.nlu.process('Show all my lists')
|
||||
|
@ -346,4 +346,4 @@ def dbCreateTodo(listname, todoname):
|
||||
'is_completed': False,
|
||||
'created_at': timestamp,
|
||||
'updated_at': timestamp
|
||||
})
|
||||
})
|
||||
|
34
scripts/clean-test-dbs.js
Normal file
34
scripts/clean-test-dbs.js
Normal file
@ -0,0 +1,34 @@
|
||||
import fs from 'fs'
|
||||
import { join } from 'path'
|
||||
|
||||
import log from '@/helpers/log'
|
||||
|
||||
/**
|
||||
* This script delete test DB files if they exist
|
||||
*/
|
||||
export default () => new Promise(async (resolve, reject) => {
|
||||
log.info('Cleaning test DB files...')
|
||||
|
||||
const packagesFolder = join(__dirname, '../packages')
|
||||
const packages = fs.readdirSync(packagesFolder)
|
||||
.filter((entity) => fs.statSync(join(packagesFolder, entity)).isDirectory())
|
||||
|
||||
for (let i = 0; i < packages.length; i += 1) {
|
||||
try {
|
||||
const dbFolder = join(packagesFolder, packages[i], 'data/db')
|
||||
const dbTestFiles = fs.readdirSync(dbFolder).filter((entity) => entity.indexOf('.spec.json') !== -1)
|
||||
|
||||
if (dbTestFiles.length > 0) {
|
||||
log.info(`Deleting ${dbTestFiles[0]}...`)
|
||||
fs.unlinkSync(join(dbFolder, dbTestFiles[0]))
|
||||
log.success(`${dbTestFiles[0]} deleted`)
|
||||
}
|
||||
} catch (e) {
|
||||
log.error(`Failed to clean: ${packages[i]} test DB file`)
|
||||
reject(e)
|
||||
}
|
||||
}
|
||||
|
||||
log.success('Cleaning done')
|
||||
resolve()
|
||||
})
|
14
scripts/run-clean-test-dbs.js
Normal file
14
scripts/run-clean-test-dbs.js
Normal file
@ -0,0 +1,14 @@
|
||||
import log from '@/helpers/log'
|
||||
|
||||
import cleanTestDbs from './clean-test-dbs'
|
||||
|
||||
/**
|
||||
* Execute the cleaning test DBs script
|
||||
*/
|
||||
(async () => {
|
||||
try {
|
||||
await cleanTestDbs()
|
||||
} catch (e) {
|
||||
log.error(`Failed to clean test DBs: ${e}`)
|
||||
}
|
||||
})()
|
@ -20,7 +20,6 @@ global.date = {
|
||||
}
|
||||
|
||||
process.env.LEON_LANG = 'en-US'
|
||||
process.env.LEON_NODE_ENV = 'testing'
|
||||
process.env.LEON_TIME_ZONE = global.date.time_zone
|
||||
|
||||
beforeAll(async () => {
|
||||
|
@ -16,7 +16,6 @@ global.audio = {
|
||||
global.enExpressions = expressions
|
||||
|
||||
process.env.LEON_LANG = 'en-US'
|
||||
process.env.LEON_NODE_ENV = 'testing'
|
||||
process.env.LEON_HOST = 'http://localhost'
|
||||
process.env.LEON_PORT = 1338
|
||||
process.env.LEON_TIME_ZONE = global.date.time_zone
|
||||
|
Loading…
Reference in New Issue
Block a user