Skip to content

Commit 357caef

Browse files
committed
cover app root case
1 parent 1beea6b commit 357caef

File tree

2 files changed

+35
-0
lines changed

2 files changed

+35
-0
lines changed
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/*
2+
* Copyright 2026 New Relic Corporation. All rights reserved.
3+
* SPDX-License-Identifier: Apache-2.0
4+
*/
5+
6+
'use strict'
7+
8+
const dc = require('node:diagnostics_channel')
9+
const resolvePackageVersion = require('../../../../../lib/subscribers/resolve-package-version')
10+
const Baz = require('./baz/index.js')
11+
12+
dc.subscribe('baz.test', handler)
13+
const baz = new Baz()
14+
baz.baz()
15+
16+
function handler() {
17+
const version = resolvePackageVersion('baz')
18+
console.log(version)
19+
process.exit(0)
20+
}

test/unit/lib/subscribers/resolve-package-version.test.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77

88
const test = require('node:test')
99
const dc = require('node:diagnostics_channel')
10+
const path = require('node:path')
11+
const { spawnSync } = require('node:child_process')
1012
const resolvePackageVersion = require('#agentlib/subscribers/resolve-package-version.js')
1113

1214
const nrPkg = require('../../../../package.json')
@@ -88,6 +90,19 @@ test('stops looking after reaching app root', (t) => {
8890
}
8991
})
9092

93+
test('returns unknown if app root does not have manifest', (t) => {
94+
const result = spawnSync(
95+
process.execPath,
96+
[
97+
'./app_root.js'
98+
],
99+
{
100+
cwd: path.join(__dirname, 'fixtures')
101+
}
102+
)
103+
t.assert.equal(result.stdout.toString(), 'unknown\n')
104+
})
105+
91106
test('returns version', (t) => {
92107
t.plan(2)
93108

0 commit comments

Comments
 (0)