Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Moar tests #228

Merged
merged 6 commits into from
Jul 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .c8rc.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"reporter": ["html", "lcov"],
"reporter": ["lcov"],
"all": true,
"exclude": ["tests/*", "coverage/*", ".eslintrc.js"]
}
}
3 changes: 3 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,8 @@ module.exports = {
extends: '@newrelic',
rules: {
'consistent-return': 'off'
},
parserOptions: {
ecmaVersion: '2020'
}
}
38 changes: 35 additions & 3 deletions THIRD_PARTY_NOTICES.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ code, the source code can be found at [https://github.com/newrelic/node-native-m
* [lockfile-lint](#lockfile-lint)
* [nock](#nock)
* [prettier](#prettier)
* [proxyquire](#proxyquire)
* [segfault-handler](#segfault-handler)
* [sinon](#sinon)
* [tap](#tap)
Expand Down Expand Up @@ -774,7 +775,7 @@ This product includes source derived from [aws-sdk](https://github.com/aws/aws-s

### c8

This product includes source derived from [c8](https://github.com/bcoe/c8) ([v7.12.0](https://github.com/bcoe/c8/tree/v7.12.0)), distributed under the [ISC License](https://github.com/bcoe/c8/blob/v7.12.0/LICENSE.txt):
This product includes source derived from [c8](https://github.com/bcoe/c8) ([v8.0.0](https://github.com/bcoe/c8/tree/v8.0.0)), distributed under the [ISC License](https://github.com/bcoe/c8/blob/v8.0.0/LICENSE.txt):

```
Copyright (c) 2017, Contributors
Expand Down Expand Up @@ -7166,6 +7167,37 @@ By: Ika

```

### proxyquire

This product includes source derived from [proxyquire](https://github.com/thlorenz/proxyquire) ([v2.1.3](https://github.com/thlorenz/proxyquire/tree/v2.1.3)), distributed under the [MIT License](https://github.com/thlorenz/proxyquire/blob/v2.1.3/LICENSE):

```
Copyright 2013 Thorsten Lorenz.
All rights reserved.

Permission is hereby granted, free of charge, to any person
obtaining a copy of this software and associated documentation
files (the "Software"), to deal in the Software without
restriction, including without limitation the rights to use,
copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following
conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.

```

### segfault-handler

This product includes source derived from [segfault-handler](https://github.com/ddopson/node-segfault-handler) ([v1.3.0](https://github.com/ddopson/node-segfault-handler/tree/v1.3.0)), distributed under the [BSD-3-Clause License](https://github.com/ddopson/node-segfault-handler/blob/v1.3.0/LICENSE):
Expand Down Expand Up @@ -7237,12 +7269,12 @@ THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

### tap

This product includes source derived from [tap](https://github.com/tapjs/node-tap) ([v16.3.2](https://github.com/tapjs/node-tap/tree/v16.3.2)), distributed under the [ISC License](https://github.com/tapjs/node-tap/blob/v16.3.2/LICENSE):
This product includes source derived from [tap](https://github.com/tapjs/node-tap) ([v16.3.7](https://github.com/tapjs/node-tap/tree/v16.3.7)), distributed under the [ISC License](https://github.com/tapjs/node-tap/blob/v16.3.7/LICENSE):

```
The ISC License

Copyright (c) 2011-2022 Isaac Z. Schlueter and Contributors
Copyright (c) 2011-2023 Isaac Z. Schlueter and Contributors

Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above
Expand Down
1 change: 1 addition & 0 deletions lib/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ const common = module.exports
common.PACKAGE_ROOT = path.resolve(__dirname, '..')
common.BUILD_PATH = path.resolve(common.PACKAGE_ROOT, './build/Release')
common.REMOTE_PATH = process.env.NR_NATIVE_METRICS_REMOTE_PATH || 'nodejs_agent/builds/'
common.IS_WIN = process.platform === 'win32'

common.parseArgs = function parseArgs(_argv, _opts) {
const args = []
Expand Down
101 changes: 101 additions & 0 deletions lib/gyp-utils.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
/*
* Copyright 2023 New Relic Corporation. All rights reserved.
* SPDX-License-Identifier: Apache-2.0
*/

'use strict'
const utils = module.exports
const fs = require('fs')
const path = require('path')
const cp = require('child_process')
const { IS_WIN } = require('./common')

/**
* This code heavily borrows from node-pre-gyp.
* https://github.com/mapbox/node-pre-gyp/blob/e0b3b6/lib/util/compile.js#L18-L55
*/
utils.findNodeGyp = function findNodeGyp() {
// First, look for it in the NPM environment variable.
let gypPath = null
if (process.env.npm_config_node_gyp) {
try {
gypPath = process.env.npm_config_node_gyp
fs.accessSync(gypPath)
return gypPath
} catch (err) {
// This method failed, hopefully the next will succeed...
}
}

// Next, see if the package is installed somewhere.
try {
// eslint-disable-next-line node/no-missing-require
const gypPkgPath = require.resolve('node-gyp')
gypPath = path.resolve(gypPkgPath, '../../bin/node-gyp.js')
fs.accessSync(gypPath)
return gypPath
} catch (err) {
// This method failed, hopefully the next will succeed...
}

// Then look for it in NPM's install location.
try {
// eslint-disable-next-line node/no-missing-require
const npmPkgPath = require.resolve('npm')
gypPath = path.resolve(npmPkgPath, '../../node_modules/node-gyp/bin/node-gyp.js')
fs.accessSync(gypPath)
return gypPath
} catch (err) {
// This method failed, hopefully the next will succeed...
}

// All of that failed, now look for it next to node itself.
const nodeNpmPkgPath = path.resolve(process.execPath, '../../lib/node_modules/npm/')
gypPath = path.join(nodeNpmPkgPath, 'node_modules/node-gyp/bin/node-gyp.js')
try {
fs.accessSync(gypPath)
return gypPath
} catch {
return null
}
}

utils.extractGypCmd = function extractGypCmd(args) {
let cmd = null
const gyp = utils.findNodeGyp()
if (gyp) {
args.unshift(gyp) // push_front
cmd = process.execPath
} else {
cmd = IS_WIN ? 'node-gyp.cmd' : 'node-gyp'
}

return cmd
}

utils.gypVersion = function gypVersion() {
const args = ['-v']
const cmd = utils.extractGypCmd(args)
const child = cp.spawnSync(cmd, args)
const match = /v(\d+\.\d+\.\d+)/.exec(child.stdout)
return match && match[1]
}

utils.execGyp = function execGyp(args, opts, cb) {
const cmd = utils.extractGypCmd(args)
const spawnOpts = {}
if (!opts.quiet) {
spawnOpts.stdio = [0, 1, 2]
}
console.log('> ' + cmd + ' ' + args.join(' ')) // eslint-disable-line no-console

const child = cp.spawn(cmd, args, spawnOpts)
child.on('error', cb)
child.on('close', function onGypClose(code) {
if (code !== 0) {
cb(new Error('Command exited with non-zero code: ' + code))
} else {
cb(null)
}
})
}
Loading