-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
re-add the original API and tests for it as a 'low-level' API, making…
… this semver minor
- Loading branch information
Showing
22 changed files
with
215 additions
and
12 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
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 |
---|---|---|
@@ -0,0 +1,13 @@ | ||
These tests have the following nomenclature: | ||
|
||
* Prefixed with `hook-` if they use the `Hook` class. | ||
* Prefixed with `ll-` if they use the "low-level" API, `addHook` and | ||
`removeHook`. | ||
|
||
The tests should be run with the `runtest` command found in this directory. If | ||
the command exits with a non-zero code, then it's a test failure. | ||
|
||
Running of all the tests can be done with `npm test`. | ||
|
||
Coverage must be 100% according to `c8`. If you don't have 100% coverage, you | ||
can run `npm run coverage` to get coverage data in HTML form. |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
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,23 @@ | ||
// Unless explicitly stated otherwise all files in this repository are licensed under the Apache 2.0 License. | ||
// | ||
// This product includes software developed at Datadog (https://www.datadoghq.com/). Copyright 2021 Datadog, Inc. | ||
|
||
const { addHook } = require('../index.js') | ||
const { strictEqual } = require('assert') | ||
|
||
addHook((name, exports) => { | ||
if (name.match(/something\.m?js/)) { | ||
const orig = exports.default | ||
exports.default = function bar() { | ||
return orig() + 15 | ||
} | ||
} | ||
}) | ||
|
||
;(async () => { | ||
const { default: barMjs } = await import('./fixtures/something.mjs') | ||
const { default: barJs } = await import('./fixtures/something.js') | ||
|
||
strictEqual(barMjs(), 57) | ||
strictEqual(barJs(), 57) | ||
})() |
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,23 @@ | ||
// Unless explicitly stated otherwise all files in this repository are licensed under the Apache 2.0 License. | ||
// | ||
// This product includes software developed at Datadog (https://www.datadoghq.com/). Copyright 2021 Datadog, Inc. | ||
|
||
import { addHook } from '../index.js' | ||
import { strictEqual } from 'assert' | ||
|
||
addHook((name, exports) => { | ||
if (name.match(/something\.m?js/)) { | ||
const orig = exports.default | ||
exports.default = function bar() { | ||
return orig() + 15 | ||
} | ||
} | ||
}) | ||
|
||
;(async () => { | ||
const { default: barMjs } = await import('./fixtures/something.mjs') | ||
const { default: barJs } = await import('./fixtures/something.js') | ||
|
||
strictEqual(barMjs(), 57) | ||
strictEqual(barJs(), 57) | ||
})() |
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,25 @@ | ||
// Unless explicitly stated otherwise all files in this repository are licensed under the Apache 2.0 License. | ||
// | ||
// This product includes software developed at Datadog (https://www.datadoghq.com/). Copyright 2021 Datadog, Inc. | ||
|
||
const { addHook } = require('../index.js') | ||
const { strictEqual } = require('assert') | ||
|
||
addHook((name, exports) => { | ||
if (name.match(/something\.m?js/)) { | ||
exports.foo += 15 | ||
} | ||
if (name.match('os')) { | ||
exports.freemem = () => 47 | ||
} | ||
}) | ||
|
||
;(async () => { | ||
const { foo: fooMjs } = await import('./fixtures/something.mjs') | ||
const { foo: fooJs } = await import('./fixtures/something.js') | ||
const { freemem } = await import('os') | ||
|
||
strictEqual(fooMjs, 57) | ||
strictEqual(fooJs, 57) | ||
strictEqual(freemem(), 47) | ||
})() |
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,25 @@ | ||
// Unless explicitly stated otherwise all files in this repository are licensed under the Apache 2.0 License. | ||
// | ||
// This product includes software developed at Datadog (https://www.datadoghq.com/). Copyright 2021 Datadog, Inc. | ||
|
||
import { addHook, removeHook } from '../index.js' | ||
import { strictEqual } from 'assert' | ||
|
||
const hook = (name, exports) => { | ||
if (name.match(/something\.m?js/)) { | ||
exports.foo += 15 | ||
} | ||
} | ||
|
||
addHook(hook) | ||
|
||
;(async () => { | ||
const { foo: fooMjs } = await import('./fixtures/something.mjs') | ||
|
||
removeHook(hook) | ||
|
||
const { foo: fooJs } = await import('./fixtures/something.js') | ||
|
||
strictEqual(fooMjs, 57) | ||
strictEqual(fooJs, 42) | ||
})() |
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,20 @@ | ||
// Unless explicitly stated otherwise all files in this repository are licensed under the Apache 2.0 License. | ||
// | ||
// This product includes software developed at Datadog (https://www.datadoghq.com/). Copyright 2021 Datadog, Inc. | ||
|
||
import { addHook } from '../index.js' | ||
import barMjs from './fixtures/something.mjs' | ||
import barJs from './fixtures/something.js' | ||
import { strictEqual } from 'assert' | ||
|
||
addHook((name, exports) => { | ||
if (name.match(/something\.m?js/)) { | ||
const orig = exports.default | ||
exports.default = function bar() { | ||
return orig() + 15 | ||
} | ||
} | ||
}) | ||
|
||
strictEqual(barMjs(), 57) | ||
strictEqual(barJs(), 57) |
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,15 @@ | ||
// Unless explicitly stated otherwise all files in this repository are licensed under the Apache 2.0 License. | ||
// | ||
// This product includes software developed at Datadog (https://www.datadoghq.com/). Copyright 2021 Datadog, Inc. | ||
|
||
import { addHook } from '../index.js' | ||
import { foo as fooMjs } from './fixtures/something.mjs' | ||
import { foo as fooJs } from './fixtures/something.js' | ||
import { strictEqual, fail } from 'assert' | ||
|
||
addHook(() => { | ||
fail('should not have been called at all') | ||
}) | ||
|
||
strictEqual(fooMjs, 42) | ||
strictEqual(fooJs, 42) |
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,22 @@ | ||
// Unless explicitly stated otherwise all files in this repository are licensed under the Apache 2.0 License. | ||
// | ||
// This product includes software developed at Datadog (https://www.datadoghq.com/). Copyright 2021 Datadog, Inc. | ||
|
||
import { addHook } from '../index.js' | ||
import { foo as fooMjs } from './fixtures/something.mjs' | ||
import { foo as fooJs } from './fixtures/something.js' | ||
import { freemem } from 'os' | ||
import { strictEqual } from 'assert' | ||
|
||
addHook((name, exports) => { | ||
if (name.match(/something\.m?js/)) { | ||
exports.foo += 15 | ||
} | ||
if (name.match('os')) { | ||
exports.freemem = () => 47 | ||
} | ||
}) | ||
|
||
strictEqual(fooMjs, 57) | ||
strictEqual(fooJs, 57) | ||
strictEqual(freemem(), 47) |