From 9a9b7aeb864284c41071fc1a14fa8bd776a49aa5 Mon Sep 17 00:00:00 2001 From: Daniel Date: Thu, 23 Jul 2020 01:56:56 +0200 Subject: [PATCH 1/2] Fxed cwd in tests --- test/consuming-services.test.js | 6 +++--- test/custom-handlers.test.js | 4 ++++ 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/test/consuming-services.test.js b/test/consuming-services.test.js index 1158452d..54a8410b 100644 --- a/test/consuming-services.test.js +++ b/test/consuming-services.test.js @@ -1,11 +1,13 @@ const { expect } = require('./capire') const cds = require('@sap/cds') + const cwd = process.cwd() +before (()=> process.chdir(__dirname)) +after(()=> process.chdir(cwd)) describe('Consuming Services locally', () => { // before('bootstrap db and services', async () => { - process.chdir(__dirname) const model = await cds.load(['@capire/bookshop', '@capire/common']) await cds.deploy(model).to('sqlite::memory:') const { AdminService } = await cds.serve('AdminService').from(model) @@ -14,8 +16,6 @@ describe('Consuming Services locally', () => { expect(Authors).not.to.be.undefined }) - after(()=> process.chdir(cwd)) - it('bootrapped the database successfully', ()=>{}) it('supports targets as strings or reflected defs', async () => { diff --git a/test/custom-handlers.test.js b/test/custom-handlers.test.js index 5efec938..4fa4fc94 100644 --- a/test/custom-handlers.test.js +++ b/test/custom-handlers.test.js @@ -1,3 +1,7 @@ +const cwd = process.cwd() +before (()=> process.chdir(__dirname)) +after(()=> process.chdir(cwd)) + describe('Custom Handlers', () => { const { GET, POST, expect } = require('./capire').launch('bookshop') From 74ee6f34e400c5c820db8a5d6590e6ae3435cabc Mon Sep 17 00:00:00 2001 From: Daniel Date: Thu, 23 Jul 2020 02:00:34 +0200 Subject: [PATCH 2/2] Fixed jest mocha --- test/custom-handlers.test.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/test/custom-handlers.test.js b/test/custom-handlers.test.js index 4fa4fc94..8c2f95d3 100644 --- a/test/custom-handlers.test.js +++ b/test/custom-handlers.test.js @@ -1,6 +1,11 @@ const cwd = process.cwd() +const is_jest = !!global.test +if (is_jest) { // it's jest + global.before = (msg,fn) => global.beforeAll(fn||msg) + global.after = (msg,fn) => global.afterAll(fn||msg) +} before (()=> process.chdir(__dirname)) -after(()=> process.chdir(cwd)) +after (()=> process.chdir(cwd)) describe('Custom Handlers', () => { const { GET, POST, expect } = require('./capire').launch('bookshop')