fixed support for mocha

This commit is contained in:
Daniel
2022-01-04 13:53:52 +01:00
committed by Daniel Hutzel
parent 788a101f41
commit a8345122ea
7 changed files with 48 additions and 21 deletions

View File

@@ -42,6 +42,7 @@
] ]
}, },
"mocha": { "mocha": {
"recursive": true,
"parallel": true "parallel": true
}, },
"license": "SAP SAMPLE CODE LICENSE", "license": "SAP SAMPLE CODE LICENSE",

View File

@@ -16,13 +16,13 @@ expect.one = (cqn) => !cqn.SELECT.distinct ? expect(cqn) : skip
describe('cds.ql → cqn', () => { describe('cds.ql → cqn', () => {
// //
for (let each of ['SELECT', 'SELECT one', 'SELECT distinct']) { describe.each(['SELECT', 'SELECT one', 'SELECT distinct'])(`%s...`, (each) => {
let SELECT; beforeEach(()=> SELECT = ( let SELECT; beforeEach(()=> SELECT = (
each === 'SELECT distinct' ? cds.ql.SELECT.distinct : each === 'SELECT distinct' ? cds.ql.SELECT.distinct :
each === 'SELECT one' ? cds.ql.SELECT.one : each === 'SELECT one' ? cds.ql.SELECT.one :
cds.ql.SELECT cds.ql.SELECT
)) ))
describe(`${each}...`, () => {
test(`from Foo`, () => { test(`from Foo`, () => {
expect(cqn = SELECT `from Foo`) expect(cqn = SELECT `from Foo`)
@@ -333,7 +333,7 @@ describe('cds.ql → cqn', () => {
}) })
}) })
})} })
describe ('SELECT where...', ()=>{ describe ('SELECT where...', ()=>{
@@ -630,6 +630,34 @@ describe('cds.ql → cqn', () => {
// //
}) })
describe(`SELECT for update`, () => {
beforeAll(() => {
delete cds.env.sql.lock_acquire_timeout
})
it('no wait', () => {
const q = SELECT.from('Foo').forUpdate()
expect(q.SELECT.forUpdate).eqls({})
})
it('specific wait', () => {
const q = SELECT.from('Foo').forUpdate({ wait: 1 })
expect(q.SELECT.forUpdate).eqls({ wait: 1 })
})
it('default wait', () => {
cds.env.sql.lock_acquire_timeout = 2
const q = SELECT.from('Foo').forUpdate()
expect(q.SELECT.forUpdate).eqls({ wait: 2 })
})
it('override default', () => {
cds.env.sql.lock_acquire_timeout = 1
const q = SELECT.from('Foo').forUpdate({ wait:-1 })
expect(q.SELECT.forUpdate).eqls({})
})
})
describe(`INSERT...`, () => { describe(`INSERT...`, () => {
test('entries ({a,b}, ...)', () => { test('entries ({a,b}, ...)', () => {
const entries = [{ foo: 1 }, { boo: 2 }] const entries = [{ foo: 1 }, { boo: 2 }]

View File

@@ -1,15 +1,13 @@
const cds = require('@sap/cds/lib') const cds = require('@sap/cds/lib')
const { expect } = cds.test ( const { expect } = cds.test ('@capire/bookshop')
'serve', 'AdminService', '--from', '@capire/bookshop,@capire/common', '--in-memory'
)
describe('Consuming Services locally', () => { describe('Consuming Services locally', () => {
// //
it('bootstrapped the database successfully', ()=>{ it('bootstrapped the database successfully', ()=>{
const { AdminService } = cds.services const { AdminService } = cds.services
const { Authors } = AdminService.entities const { Authors } = AdminService.entities
expect(AdminService).not.to.be.undefined expect(AdminService).to.exist
expect(Authors).not.to.be.undefined expect(Authors).to.exist
}) })
it('supports targets as strings or reflected defs', async () => { it('supports targets as strings or reflected defs', async () => {
@@ -39,6 +37,7 @@ describe('Consuming Services locally', () => {
name: 'Emily Brontë', name: 'Emily Brontë',
books: [ books: [
{ {
ID: 201,
title: 'Wuthering Heights', title: 'Wuthering Heights',
currency: { name: 'British Pound', symbol: '£' }, currency: { name: 'British Pound', symbol: '£' },
}, },
@@ -47,8 +46,8 @@ describe('Consuming Services locally', () => {
{ {
name: 'Edgar Allen Poe', name: 'Edgar Allen Poe',
books: [ books: [
{ title: 'The Raven', currency: { name: 'US Dollar', symbol: '$' } }, { ID: 251, title: 'The Raven', currency: { name: 'US Dollar', symbol: '$' } },
{ title: 'Eleonora', currency: { name: 'US Dollar', symbol: '$' } }, { ID: 252, title: 'Eleonora', currency: { name: 'US Dollar', symbol: '$' } },
], ],
}, },
]) ])

View File

@@ -9,8 +9,7 @@ describe('Hello world!', () => {
}) })
it('should say hello with another impl', async () => { it('should say hello with another impl', async () => {
const cds = require ('@sap/cds') await cds.serve('say').from(cds.model)
cds.serve('say').from(cds.model)
.at('/say-again').in(cds.app) .at('/say-again').in(cds.app)
.with(srv => { .with(srv => {
srv.on('hello', (req) => `Hello again ${req.data.to}!`) srv.on('hello', (req) => `Hello again ${req.data.to}!`)

View File

@@ -1,5 +1,4 @@
const cds = require('@sap/cds/lib') const { GET, expect, cds } = require('@sap/cds/lib').test (__dirname)
const { GET, expect } = cds.test.run ('serve', __dirname+'/localized-data.cds', '--in-memory')
if (cds.User.default) cds.User.default = cds.User.Privileged // hard core monkey patch if (cds.User.default) cds.User.default = cds.User.Privileged // hard core monkey patch
else cds.User = cds.User.Privileged // hard core monkey patch for older cds releases else cds.User = cds.User.Privileged // hard core monkey patch for older cds releases

View File

@@ -1,7 +1,8 @@
const cds = require('@sap/cds/lib')
const { expect } = cds.test
const { fork } = require('child_process') const { fork } = require('child_process')
const { resolve } = require('path') const { resolve } = require('path')
const Axios = require('axios')
const verbose = process.env.CDS_TEST_VERBOSE const verbose = process.env.CDS_TEST_VERBOSE
// ||true // ||true
@@ -10,28 +11,28 @@ describe('Local NPM registry', () => {
let axios let axios
const cwd = resolve(__dirname, '..') const cwd = resolve(__dirname, '..')
beforeAll(async ()=> { before(async ()=> {
const env = Object.assign(process.env, {PORT:'0'}) const env = Object.assign(process.env, {PORT:'0'})
const res = await exec (resolve(cwd, '.registry/server.js'), {cwd, stdio: 'pipe', env}) const res = await exec (resolve(cwd, '.registry/server.js'), {cwd, stdio: 'pipe', env})
registry = res.cp registry = res.cp
axios = Axios.default.create ({ baseURL: res.url, validateStatus: (status)=>status<500 }) axios = require('axios').default.create ({ baseURL: res.url, validateStatus: (status)=>status<500 })
}) })
afterAll(() => { registry.kill() }) after(() => { registry.kill() })
for (const mod of ['bookshop','fiori','orders','reviews']) { for (const mod of ['bookshop','fiori','orders','reviews']) {
it(`should serve ${mod}`, async () => { it(`should serve ${mod}`, async () => {
const resp = await axios.get(`/@capire/${mod}`) const resp = await axios.get(`/@capire/${mod}`)
expect(resp.data).toMatchObject({name: `@capire/${mod}`, versions:{}}) expect(resp.data).to.containSubset({name: `@capire/${mod}`, versions:{}})
const versions = Object.values(resp.data.versions) const versions = Object.values(resp.data.versions)
await axios.get(versions[0].dist.tarball) await axios.get(versions[0].dist.tarball)
}) })
} }
it(`should return 404 for unknown packages`, async () => { it(`should return 404 for unknown packages`, async () => {
let resp = await axios.get(`/@capire/foo`) let resp = await axios.get(`/@capire/foo`)
expect(resp.status).toEqual(404) expect(resp.status).to.equal(404)
resp = await axios.get(`/foo`) resp = await axios.get(`/foo`)
expect(resp.status).toEqual(404) expect(resp.status).to.equal(404)
}) })
}) })