forked from newrelic/node-newrelic
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: Migrated elasticsearch and esm-package versioned tests to `node…
…:test` (newrelic#2680)
- Loading branch information
Showing
7 changed files
with
243 additions
and
346 deletions.
There are no files selected for viewing
382 changes: 145 additions & 237 deletions
382
test/versioned/elastic/elasticsearch.tap.js → test/versioned/elastic/elasticsearch.test.js
Large diffs are not rendered by default.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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,59 @@ | ||
/* | ||
* Copyright 2020 New Relic Corporation. All rights reserved. | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
'use strict' | ||
const test = require('node:test') | ||
const assert = require('node:assert') | ||
const helper = require('../../lib/agent_helper') | ||
const params = require('../../lib/params') | ||
const crypto = require('crypto') | ||
const DB_INDEX = `test-${randomString()}` | ||
|
||
function randomString() { | ||
return crypto.randomBytes(5).toString('hex') | ||
} | ||
|
||
test('Elasticsearch instrumentation', async (t) => { | ||
t.beforeEach(async (ctx) => { | ||
const agent = helper.instrumentMockedAgent() | ||
|
||
// need to capture attributes | ||
agent.config.attributes.enabled = true | ||
const { Client } = require('@elastic/elasticsearch') | ||
|
||
const client = new Client({ | ||
node: `http://${params.elastic_host}:${params.elastic_port}` | ||
}) | ||
ctx.nr = { | ||
agent, | ||
client | ||
} | ||
}) | ||
|
||
t.afterEach((ctx) => { | ||
helper.unloadAgent(ctx.nr.agent) | ||
}) | ||
|
||
await t.test( | ||
'unsupported version should noop db tracing, but record web transaction', | ||
async (t) => { | ||
const { agent, client } = t.nr | ||
await helper.runInTransaction(agent, async function transactionInScope(transaction) { | ||
try { | ||
await client.indices.create({ index: DB_INDEX }) | ||
} catch (e) { | ||
assert.ok(!e, 'should not error') | ||
} | ||
const firstChild = transaction?.trace?.root?.children[0] | ||
assert.equal( | ||
firstChild.name, | ||
`External/localhost:9200/${DB_INDEX}`, | ||
'should record index creation as an external transaction' | ||
) | ||
await client.indices.delete({ index: DB_INDEX }) | ||
}) | ||
} | ||
) | ||
}) |
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 |
---|---|---|
|
@@ -13,7 +13,7 @@ | |
"parse-json": "6.0.2" | ||
}, | ||
"files": [ | ||
"parse-json.tap.mjs" | ||
"parse-json.test.mjs" | ||
] | ||
} | ||
], | ||
|
This file was deleted.
Oops, something went wrong.
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,36 @@ | ||
/* | ||
* Copyright 2024 New Relic Corporation. All rights reserved. | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
import test from 'node:test' | ||
import assert from 'node:assert' | ||
import helper from '../../lib/agent_helper.js' | ||
import shimmer from '../../../lib/shimmer.js' | ||
import parseJsonInstrumentation from './parse-json-instrumentation.mjs' | ||
|
||
shimmer.registerInstrumentation({ | ||
moduleName: 'parse-json', | ||
type: 'generic', | ||
isEsm: true, | ||
onRequire: parseJsonInstrumentation | ||
}) | ||
|
||
test('ESM Package Instrumentation', async (t) => { | ||
const agent = helper.instrumentMockedAgent() | ||
const { default: parseJson, JSONError } = await import('parse-json') | ||
|
||
t.after(() => { | ||
helper.unloadAgent(agent) | ||
}) | ||
|
||
await t.test('should register instrumentation on default exports', () => { | ||
const output = parseJson(JSON.stringify({ foo: 'bar' })) | ||
assert.ok(output.isInstrumented, 'should have the field we add in our test instrumentation') | ||
}) | ||
|
||
await t.test('should register instrumentation on named exports', () => { | ||
const err = new JSONError('test me') | ||
assert.ok(err.isInstrumented, 'JSONError should be instrumented') | ||
}) | ||
}) |