-
Notifications
You must be signed in to change notification settings - Fork 1
fix(NODE-6606): install bson libraries to tmp directory #24
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
Merged
Changes from 5 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
5ef84f2
add 22 to matrix and test on latest
W-A-James a9a0893
change where packages are installed
W-A-James 60f3262
add test to ensure that temp directory is created and removed
W-A-James a1e1697
add package test
W-A-James e1639ea
revert update to ci
W-A-James 1f1b6b0
review fixes
W-A-James f904974
fix local path change
W-A-James File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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,27 +1,42 @@ | ||
| import { expect } from 'chai'; | ||
| import { sep } from 'path'; | ||
| import { mkdir, rm } from 'fs/promises'; | ||
| import { tmpdir } from 'os'; | ||
| import { join, sep } from 'path'; | ||
|
|
||
| import { Package } from '../../lib/common'; | ||
| import { clearTestedDeps } from '../utils'; | ||
| import { clearTestedDeps, exists } from '../utils'; | ||
|
|
||
| describe('common functionality', function () { | ||
| const BSON_PATH = process.env.BSON_PATH; | ||
|
|
||
| context('Package', function () { | ||
| beforeEach(clearTestedDeps); | ||
| after(clearTestedDeps); | ||
| let installDir: string; | ||
|
|
||
| after(async function () { | ||
| await rm(installDir, { recursive: true, force: true }); | ||
| }); | ||
|
|
||
| beforeEach(async function () { | ||
| await clearTestedDeps(installDir); | ||
| }); | ||
|
|
||
| before(async function () { | ||
| installDir = join(tmpdir(), 'bsonBenchTest'); | ||
| await mkdir(installDir); | ||
| }); | ||
|
|
||
| context('constructor()', function () { | ||
| //github.com/mongodb-js/dbx-js-tools/pull/24/files | ||
| context('when given a correctly formatted npm package', function () { | ||
| it('sets computedModuleName correctly', function () { | ||
| const pack = new Package('[email protected]'); | ||
| const pack = new Package('[email protected]', installDir); | ||
| expect(pack).to.haveOwnProperty('computedModuleName', 'bson-6.0.0'); | ||
| }); | ||
| }); | ||
|
|
||
| context('when given a correctly formatted git repository', function () { | ||
| it('sets computedModuleName correctly', function () { | ||
| const pack = new Package('bson#eb98b8c39d6d5ba4ce7231ab9e0f29495d74b994'); | ||
| const pack = new Package('bson#eb98b8c39d6d5ba4ce7231ab9e0f29495d74b994', installDir); | ||
| expect(pack).to.haveOwnProperty( | ||
| 'computedModuleName', | ||
| 'bson-git-eb98b8c39d6d5ba4ce7231ab9e0f29495d74b994' | ||
|
|
@@ -31,13 +46,16 @@ describe('common functionality', function () { | |
|
|
||
| context('when trying to install an npm package apart from bson or bson-ext', function () { | ||
| it('throws an error', function () { | ||
| expect(() => new Package('[email protected]')).to.throw(Error, /unknown package specifier/); | ||
| expect(() => new Package('[email protected]', installDir)).to.throw( | ||
| Error, | ||
| /unknown package specifier/ | ||
| ); | ||
| }); | ||
| }); | ||
|
|
||
| context('when trying to install a git package apart from bson or bson-ext', function () { | ||
| it('throws an error', function () { | ||
| expect(() => new Package('notBson#abcdabcdabcd')).to.throw( | ||
| expect(() => new Package('notBson#abcdabcdabcd', installDir)).to.throw( | ||
| Error, | ||
| /unknown package specifier/ | ||
| ); | ||
|
|
@@ -50,7 +68,7 @@ describe('common functionality', function () { | |
| console.log('Skipping since BSON_PATH is undefined'); | ||
| this.skip(); | ||
| } | ||
| const pack = new Package(`bson:${BSON_PATH}`); | ||
| const pack = new Package(`bson:${BSON_PATH}`, installDir); | ||
| expect(pack).to.haveOwnProperty( | ||
| 'computedModuleName', | ||
| `bson-local-${BSON_PATH.replaceAll(sep, '_')}` | ||
|
|
@@ -62,14 +80,14 @@ describe('common functionality', function () { | |
| context('#check()', function () { | ||
| context('when package is not installed', function () { | ||
| it('returns undefined', function () { | ||
| const pack = new Package('bson@6'); | ||
| const pack = new Package('bson@6', installDir); | ||
| expect(pack.check()).to.be.undefined; | ||
| }); | ||
| }); | ||
|
|
||
| context('when package is installed', function () { | ||
| it('returns the module', async function () { | ||
| const pack = new Package('[email protected]'); | ||
| const pack = new Package('[email protected]', installDir); | ||
| await pack.install(); | ||
| expect(pack.check()).to.not.be.undefined; | ||
| }); | ||
|
|
@@ -79,26 +97,31 @@ describe('common functionality', function () { | |
| context('#install()', function () { | ||
| context('when given a correctly formatted npm package that exists', function () { | ||
| for (const lib of ['[email protected]', '[email protected]', 'bson@latest', 'bson-ext@latest']) { | ||
| it(`installs ${lib} successfully`, async function () { | ||
| const pack = new Package(lib); | ||
| it(`installs ${lib} successfully to the specified install directory`, async function () { | ||
| const pack = new Package(lib, installDir); | ||
| await pack.install(); | ||
|
|
||
| expect(await exists(join(installDir, 'node_modules', pack.computedModuleName))).to.be | ||
| .true; | ||
| }); | ||
| } | ||
| }); | ||
|
|
||
| context('when given a correctly formatted npm package that does not exist', function () { | ||
| it('throws an error', async function () { | ||
| const bson9000 = new Package('bson@9000'); | ||
| const bson9000 = new Package('bson@9000', installDir); | ||
| const error = await bson9000.install().catch(error => error); | ||
| expect(error).to.be.instanceOf(Error); | ||
| }); | ||
| }); | ||
|
|
||
| context('when given a correctly formatted git package using commit that exists', function () { | ||
| it('installs successfully', async function () { | ||
| const bson6Git = new Package('bson#58c002d'); | ||
| it('installs successfully to specified install directory', async function () { | ||
| const bson6Git = new Package('bson#58c002d', installDir); | ||
| const maybeError = await bson6Git.install().catch(error => error); | ||
| expect(maybeError).to.be.undefined; | ||
| expect(await exists(join(installDir, 'node_modules', bson6Git.computedModuleName))).to.be | ||
| .true; | ||
| }); | ||
| }); | ||
|
|
||
|
|
@@ -107,7 +130,10 @@ describe('common functionality', function () { | |
| function () { | ||
| // TODO: NODE-6361: Unskip and fix this test. | ||
| it.skip('throws an error', async function () { | ||
| const bson6Git = new Package('bson#58c002d87bca9bbe7c7001cc6acae54e90a951bcf'); | ||
| const bson6Git = new Package( | ||
| 'bson#58c002d87bca9bbe7c7001cc6acae54e90a951bcf', | ||
| installDir | ||
| ); | ||
| const maybeError = await bson6Git.install().catch(error => error); | ||
| expect(maybeError).to.be.instanceOf(Error); | ||
| }); | ||
|
|
@@ -118,9 +144,11 @@ describe('common functionality', function () { | |
| 'when given a correctly formatted git package using git tag that exists', | ||
| function () { | ||
| it('installs successfully', async function () { | ||
| const bson6Git = new Package('bson#v6.0.0'); | ||
| const bson6Git = new Package('bson#v6.0.0', installDir); | ||
| const maybeError = await bson6Git.install().catch(error => error); | ||
| expect(maybeError).to.be.undefined; | ||
| expect(await exists(join(installDir, 'node_modules', bson6Git.computedModuleName))).to | ||
| .be.true; | ||
| }); | ||
| } | ||
| ); | ||
|
|
@@ -129,7 +157,7 @@ describe('common functionality', function () { | |
| 'when given a correctly formatted git package using git tag that does not exist', | ||
| function () { | ||
| it('throws an error', async function () { | ||
| const bson6Git = new Package('bson#v999.999.9'); | ||
| const bson6Git = new Package('bson#v999.999.9', installDir); | ||
| const maybeError = await bson6Git.install().catch(error => error); | ||
| expect(maybeError).to.be.instanceOf(Error); | ||
| }); | ||
|
|
@@ -143,16 +171,19 @@ describe('common functionality', function () { | |
| this.skip(); | ||
| } | ||
|
|
||
| const bsonLocal = new Package(`bson:${BSON_PATH}`); | ||
| const bsonLocal = new Package(`bson:${BSON_PATH}`, installDir); | ||
| const maybeError = await bsonLocal.install().catch(error => error); | ||
| expect(maybeError).to.not.be.instanceOf(Error, maybeError.message); | ||
| expect(await exists(join(installDir, 'node_modules', bsonLocal.computedModuleName))).to.be | ||
| .true; | ||
| }); | ||
| }); | ||
|
|
||
| context('when given a path that does not exist', function () { | ||
| it('throws an error', async function () { | ||
| const bsonLocal = new Package( | ||
| `bson:/highly/unlikely/path/to/exist/that/should/point/to/bson` | ||
| `bson:/highly/unlikely/path/to/exist/that/should/point/to/bson`, | ||
| installDir | ||
| ); | ||
| const maybeError = await bsonLocal.install().catch(error => error); | ||
| expect(maybeError).to.be.instanceOf(Error); | ||
|
|
||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.