-
Notifications
You must be signed in to change notification settings - Fork 79
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: 🐛 only download binary if PACT_SKIP_BINARY_INSTALL is true
- Loading branch information
1 parent
1143af5
commit 69cbba0
Showing
13 changed files
with
8,338 additions
and
3,310 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
module.exports = { | ||
exclude: '**/*.jest.spec.ts', | ||
require: 'ts-node/register', | ||
timeout: '30000', | ||
slow: '5000', | ||
exit: true, | ||
require: 'ts-node.js', | ||
'check-leaks': true, | ||
}; |
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 +1 @@ | ||
require("./standalone/install").downloadChecksums(); | ||
require('./standalone/install').downloadChecksums(); |
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,9 @@ | ||
module.exports = { | ||
testMatch: ['**/?(*.)jest.spec.ts'], | ||
transform: { '^.+\\.(ts)$': 'ts-jest' }, | ||
globals: { | ||
'ts-jest': { | ||
tsconfig: 'tsconfig.spec.json', | ||
}, | ||
}, | ||
}; |
Large diffs are not rendered by default.
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
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,29 @@ | ||
interface Files { | ||
[fileName: string]: string; | ||
} | ||
|
||
export interface FS { | ||
initFS: (files: Files) => void; | ||
existsSync: (path: string) => boolean; | ||
} | ||
|
||
const mockFS: FS = jest.genMockFromModule('fs'); | ||
|
||
let mockedFiles: Files = {}; | ||
|
||
function initFS(mockFiles: Files): void { | ||
mockedFiles = mockFiles; | ||
|
||
Object.keys(mockFiles).forEach(filePath => { | ||
jest.mock(filePath, () => mockFiles[filePath], { virtual: true }); | ||
}); | ||
} | ||
|
||
function existsSync(path: string): boolean { | ||
return !!mockedFiles[path]; | ||
} | ||
|
||
mockFS.initFS = initFS; | ||
mockFS.existsSync = existsSync; | ||
|
||
module.exports = mockFS; |
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,135 @@ | ||
import * as fs from 'fs'; | ||
import * as path from 'path'; | ||
import install, { BinaryEntry, createConfig, getBinaryEntry } from './install'; | ||
import { FS } from './__mocks__/fs'; | ||
|
||
jest.mock('fs'); | ||
jest.mock('sumchecker', () => | ||
jest.fn().mockImplementation(() => Promise.resolve()), | ||
); | ||
jest.mock('libnpmconfig', () => ({ | ||
read: (): jest.Mock => jest.fn(), | ||
})); | ||
jest.mock('tar'); | ||
|
||
describe('Install', () => { | ||
const packageBasePath: string = path.resolve(__dirname, '__fixtures__'); | ||
const packagePath: string = path.resolve(packageBasePath, 'package.json'); | ||
|
||
// eslint-disable-next-line @typescript-eslint/no-var-requires | ||
let packageConfig = JSON.parse(JSON.stringify(require('../package.json'))); | ||
let OLD_ENV: { [key: string]: string | undefined }; | ||
|
||
function initFS(config: { | ||
pact_binary_location?: string; | ||
pact_do_not_track?: boolean; | ||
}): void { | ||
((fs as unknown) as FS).initFS({ | ||
[packagePath]: { | ||
...packageConfig, | ||
config, | ||
}, | ||
}); | ||
} | ||
|
||
beforeEach(() => { | ||
jest.resetModules(); | ||
OLD_ENV = { ...process.env }; | ||
}); | ||
|
||
afterEach(() => { | ||
process.env = { ...OLD_ENV }; | ||
}); | ||
|
||
describe('Package.json Configuration', () => { | ||
describe('Binary Location', () => { | ||
it('Should be able to set binary location as an absolute path', () => { | ||
// eslint-disable-next-line @typescript-eslint/camelcase | ||
const pact_binary_location = '/some-location/or-other'; | ||
initFS({ | ||
// eslint-disable-next-line @typescript-eslint/camelcase | ||
pact_binary_location, | ||
}); | ||
const config = createConfig(packageBasePath); | ||
config.binaries.forEach((entry: BinaryEntry) => { | ||
expect(entry.downloadLocation).toEqual( | ||
path.resolve(pact_binary_location), | ||
); | ||
}); | ||
}); | ||
|
||
it('Should be able to set binary location as an relative path', () => { | ||
// eslint-disable-next-line @typescript-eslint/camelcase | ||
const pact_binary_location = 'some-location/or-other'; | ||
// eslint-disable-next-line @typescript-eslint/camelcase | ||
initFS({ pact_binary_location }); | ||
const config = createConfig(packageBasePath); | ||
config.binaries.forEach((entry: BinaryEntry) => { | ||
expect(entry.downloadLocation).toEqual( | ||
path.resolve(packageBasePath, pact_binary_location), | ||
); | ||
}); | ||
}); | ||
|
||
it('Should be able to set binary location as an HTTP URL', () => { | ||
// eslint-disable-next-line @typescript-eslint/camelcase | ||
const pact_binary_location = 'http://some.url'; | ||
// eslint-disable-next-line @typescript-eslint/camelcase | ||
initFS({ pact_binary_location }); | ||
const config = createConfig(packageBasePath); | ||
config.binaries.forEach((entry: BinaryEntry) => { | ||
expect(entry.downloadLocation).toEqual(pact_binary_location); | ||
}); | ||
}); | ||
|
||
it('Should be able to set binary location as an HTTPS URL', () => { | ||
// eslint-disable-next-line @typescript-eslint/camelcase | ||
const pact_binary_location = 'https://some.url'; | ||
// eslint-disable-next-line @typescript-eslint/camelcase | ||
initFS({ pact_binary_location }); | ||
const config = createConfig(packageBasePath); | ||
config.binaries.forEach((entry: BinaryEntry) => { | ||
expect(entry.downloadLocation).toEqual(pact_binary_location); | ||
}); | ||
}); | ||
}); | ||
|
||
it("Should be able to set 'do not track' from package.json config", () => { | ||
// eslint-disable-next-line @typescript-eslint/camelcase | ||
const pact_do_not_track = true; | ||
// eslint-disable-next-line @typescript-eslint/camelcase | ||
initFS({ pact_do_not_track }); | ||
const config = createConfig(packageBasePath); | ||
expect(config.doNotTrack).toEqual(pact_do_not_track); | ||
}); | ||
}); | ||
|
||
describe('Environment variables configuration', () => { | ||
it("Should be able to set 'do not track' from environment variable 'PACT_DO_NOT_TRACK'", () => { | ||
const doNotTrack = true; | ||
process.env.PACT_DO_NOT_TRACK = `${doNotTrack}`; | ||
const config = createConfig(packageBasePath); | ||
expect(config.doNotTrack).toEqual(doNotTrack); | ||
}); | ||
}); | ||
|
||
describe('Skip install binary', () => { | ||
it('Should not download it', async () => { | ||
process.env.PACT_SKIP_BINARY_INSTALL = 'true'; | ||
const { binaryInstallSkipped } = await install('linux', 'ia32'); | ||
expect(binaryInstallSkipped).toBeTruthy(); | ||
}); | ||
|
||
it('Should download it', async () => { | ||
const { binaryChecksum, binary } = getBinaryEntry('linux', 'ia32'); | ||
((fs as unknown) as FS).initFS({ | ||
[path.join(__dirname, binary)]: 'mock binary', | ||
[path.join(__dirname, binaryChecksum)]: 'mock binary checksum', | ||
}); | ||
|
||
process.env.PACT_SKIP_BINARY_INSTALL = 'false'; | ||
const { binaryInstallSkipped } = await install('linux', 'ia32'); | ||
expect(binaryInstallSkipped).toBeFalsy(); | ||
}); | ||
}); | ||
}); |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.