Skip to content

Commit 3583130

Browse files
daogradychgeo
andauthored
Run typer once before cds watch starts (#517)
Shoehorn tests for #506 --------- Co-authored-by: Christian Georgi <[email protected]> Co-authored-by: Christian Georgi <[email protected]>
1 parent c6f9aba commit 3583130

File tree

3 files changed

+47
-3
lines changed

3 files changed

+47
-3
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ All notable changes to this project will be documented in this file.
88
- Improved performance of repeated `cds-typer` runs by introducing an option to cache CDS model between runs. By default, typer will only regenerate the files if the model has changed between runs, using `blake2s256` as algorithm.
99
### Changed
1010
- [breaking] The config `use_entities_proxy` (allowing for static imports) is now set to `true` as default. You can set it to `false` to revert to the old behaviour.
11+
- Running `cds watch` will trigger `cds-typer "*"` before the initial startup
1112
### Deprecated
1213
### Removed
1314
### Fixed
@@ -17,7 +18,6 @@ All notable changes to this project will be documented in this file.
1718

1819
### Added
1920
### Changed
20-
- Running `cds watch` will trigger `cds-typer "*"` before the initial startup
2121
### Deprecated
2222
### Removed
2323
### Fixed

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@
1616
"test:unit": "node test/testRunner.js ./test/unit ./test/unit/setup.mjs",
1717
"test:integration": "node test/testRunner.js ./test/integration ./test/integration/setup.mjs",
1818
"test:smoke": "node test/testRunner.js ./test/smoke ./test/smoke/setup.mjs",
19-
"test:all": "npm run test:smoke && npm run test:unit",
20-
"test": "npm run test:smoke && npm run test:unit",
19+
"test:all": "npm run test:smoke && npm run test:unit && npm run test:integration",
20+
"test": "npm run test:all",
2121
"lint": "npx eslint .",
2222
"lint:fix": "npx eslint . --fix",
2323
"cli": "node lib/cli.js",

test/integration/cds-watch.test.js

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
'use strict'
2+
3+
const fs = require('node:fs')
4+
const path = require('node:path')
5+
const { describe, it, before } = require('node:test')
6+
const assert = require('node:assert')
7+
const { execSync } = require('node:child_process')
8+
const cds = require('@sap/cds')
9+
10+
const dir = path.join(__dirname, 'dummy-project')
11+
// use a slightly different model directory to avoid race-conditions with
12+
// vscode, as our extension eagerly creates @cds-models when creating a new .cds file
13+
// as part of our tests
14+
const modelsDir = path.join(dir, '@cds-models-test')
15+
const logs = []
16+
17+
describe('cds watch', () => {
18+
before(async () => {
19+
// spy on cds.debug('cli|build')
20+
const cdsLog = cds.debug
21+
cds.debug = (...args) => {
22+
return args[0] === 'cli|build'
23+
? (...largs) => {
24+
logs.push(args, largs)
25+
return cdsLog(...args)(...largs)
26+
}
27+
: cdsLog(...args)}
28+
})
29+
30+
it('runs once before cds watch', async () => {
31+
await fs.promises.rm(modelsDir, { recursive: true, force: true })
32+
cds.watched = true
33+
cds.root = dir
34+
// need to set manually, as we don't go through the regular cds bootstrap
35+
cds.env.typer = { output_directory: modelsDir }
36+
cds.env.log.levels.cli = 'debug'
37+
await require('../../cds-plugin')
38+
assert.ok(logs.some(log => log.some(line => line.match(/start.*cds-typer/))))
39+
logs.length = 0
40+
await require('../../cds-plugin')
41+
// should not run when models are already there
42+
assert.ok(!logs.some(log => log.some(line => line.match(/end.*cds-typer/))))
43+
})
44+
})

0 commit comments

Comments
 (0)