-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(NODE-6606): install bson libraries to tmp directory (#24)
- Loading branch information
Showing
7 changed files
with
204 additions
and
73 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 |
---|---|---|
@@ -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.