-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: only startup plugin if invoked for runtime (#185)
- Loading branch information
Showing
6 changed files
with
73 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,12 @@ | ||
if (!process.env.NO_TELEMETRY || process.env.NO_TELEMETRY === 'false') require('./lib')() | ||
let _startup = true | ||
|
||
const cds = require('@sap/cds') | ||
if (!(cds.cli?.command in { '': 1, serve: 1, run: 1 })) _startup = false | ||
|
||
// cds add XXX currently also has cli.command === '' | ||
const i = process.argv.indexOf('add') | ||
if (i > 1 && process.argv[i - 1].match(/cds(\.js)?$/)) _startup = false | ||
|
||
if (!!process.env.NO_TELEMETRY && process.env.NO_TELEMETRY !== 'false') _startup = false | ||
|
||
if (_startup) require('./lib')() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
{ | ||
"name": "bookshop", | ||
"dependencies": { | ||
"@cap-js/telemetry": "*", | ||
"@cap-js/sqlite": "*", | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
const childProcess = require('child_process') | ||
|
||
const startup = cmd => { | ||
return new Promise(resolve => { | ||
const p = childProcess.exec(cmd, { | ||
env: Object.assign({}, process.env, { CDS_REQUIRES_TELEMETRY_KIND: 'to-cloud-logging' }), | ||
cwd: __dirname + '/bookshop' | ||
}) | ||
p.on('exit', () => { | ||
resolve(!p.exitCode ? false : true) | ||
}) | ||
p.stdout.on('data', data => { | ||
if (data.match(/server listening on/)) p.kill() | ||
}) | ||
}) | ||
} | ||
|
||
describe('plugin started', () => { | ||
afterAll(() => { | ||
require('fs').unlinkSync(__dirname + '/bookshop/mta.yaml') | ||
require('fs').rmdirSync(__dirname + '/bookshop/gen', { recursive: true }) | ||
}) | ||
|
||
test('not for NO_TELEMETRY=true', async () => { | ||
const started = await startup('NO_TELEMETRY=true cds serve') | ||
expect(started).toBe(false) | ||
}) | ||
|
||
test('for NO_TELEMETRY=false', async () => { | ||
const started = await startup('NO_TELEMETRY=false cds serve') | ||
expect(started).toBe(true) | ||
}) | ||
|
||
test('for cds serve', async () => { | ||
const started = await startup('cds serve') | ||
expect(started).toBe(true) | ||
}) | ||
|
||
test('for cds run', async () => { | ||
const started = await startup('cds run') | ||
expect(started).toBe(true) | ||
}) | ||
|
||
test('not for cds build', async () => { | ||
const started = await startup('cds build --production') | ||
expect(started).toBe(false) | ||
}) | ||
|
||
test('not for cds add', async () => { | ||
const started = await startup('cds add mta') | ||
expect(started).toBe(false) | ||
}) | ||
}) |