Add example for starting cds with ts-node
This commit is contained in:
@@ -2,6 +2,7 @@
|
|||||||
"name": "@capire/hello-world",
|
"name": "@capire/hello-world",
|
||||||
"version": "1.0.0",
|
"version": "1.0.0",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"watch": "cds serve world.cds"
|
"watch": "cds serve world.cds",
|
||||||
|
"watch:ts": "npx ts-node ../node_modules/@sap/cds/bin/cds serve world.cds"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
5
hello/world.ts
Normal file
5
hello/world.ts
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
module.exports = class say {
|
||||||
|
hello(req: any) {
|
||||||
|
return `Hello ${req.data.to} from a typescript file!`
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -16,11 +16,14 @@
|
|||||||
"express": "^4"
|
"express": "^4"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
|
"@types/jest": "^26.0.23",
|
||||||
|
"@types/node": "^15.12.0",
|
||||||
"cds-swagger-ui-express": "^0.2.0",
|
"cds-swagger-ui-express": "^0.2.0",
|
||||||
"chai": "^4.2.0",
|
"chai": "^4.2.0",
|
||||||
"chai-as-promised": "^7.1.1",
|
"chai-as-promised": "^7.1.1",
|
||||||
"chai-subset": "^1.6.0",
|
"chai-subset": "^1.6.0",
|
||||||
"sqlite3": "^5.0.0"
|
"sqlite3": "^5.0.0",
|
||||||
|
"ts-jest": "^27.0.2"
|
||||||
},
|
},
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"cleanup": "rm -rf node_modules && rm -rf */node_modules && rm -rf */*/node_modules",
|
"cleanup": "rm -rf node_modules && rm -rf */node_modules && rm -rf */*/node_modules",
|
||||||
@@ -30,7 +33,8 @@
|
|||||||
"media": "cds watch media",
|
"media": "cds watch media",
|
||||||
"mocha": "npx mocha || echo",
|
"mocha": "npx mocha || echo",
|
||||||
"jest": "npx jest",
|
"jest": "npx jest",
|
||||||
"test": "npm run jest --silent"
|
"test": "npm run jest --silent --testMatch test/*.test.js && npm run test:ts",
|
||||||
|
"test:ts": "npm run jest --silent --preset ts-jest --testMatch test/*.test.ts"
|
||||||
},
|
},
|
||||||
"mocha": {
|
"mocha": {
|
||||||
"parallel": true
|
"parallel": true
|
||||||
|
|||||||
13
test/hello-world-ts.test.ts
Normal file
13
test/hello-world-ts.test.ts
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
const testKit = require('../test')
|
||||||
|
process.env.TYPESCRIPT_SUPPORT = 'true';
|
||||||
|
|
||||||
|
const {GET} = testKit.run('serve', 'hello/world.cds')
|
||||||
|
|
||||||
|
describe('Hello world!', () => {
|
||||||
|
|
||||||
|
it('should say hello with class impl from a typescript file', async () => {
|
||||||
|
const {data} = await GET`/say/hello(to='world')`
|
||||||
|
expect(data.value).toEqual('Hello world from a typescript file!')
|
||||||
|
})
|
||||||
|
|
||||||
|
})
|
||||||
Reference in New Issue
Block a user