This repository has been archived by the owner on Nov 4, 2024. It is now read-only.
generated from tophat/new-project-kit
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: aggregate verify conditions error (#33)
* chore: bump semantic-release to 16.0.1 * fix: include semantic-release in peer deps * wip: add e2e * wip: run e2e * wip: remove e2e yarn lock * fix: use aggregate error in verify conditions * test: prepare * test: publish * test: verify conditions
- Loading branch information
Showing
15 changed files
with
425 additions
and
103 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 @@ | ||
yarn.lock |
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 @@ | ||
{ | ||
"dependencies": { | ||
"web-ext": "^4.0.0", | ||
"semantic-release": "^16.0.0" | ||
}, | ||
"scripts": { | ||
"test-e2e": "../node_modules/.bin/semantic-release" | ||
}, | ||
"release": { | ||
"dryRun": true, | ||
"plugins": [ | ||
[ | ||
"../src/index.js", | ||
{ | ||
"artifactsDir": "./", | ||
"extensionId": "{01234567-abcd-6789-cdef-0123456789ef}", | ||
"targetXpi": "extension.xpi" | ||
} | ||
] | ||
] | ||
} | ||
} |
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
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,3 @@ | ||
const { fs } = require('memfs') | ||
|
||
module.exports = fs |
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,6 @@ | ||
const mockWebExt = { | ||
cmd: { | ||
sign: jest.fn(), | ||
}, | ||
} | ||
module.exports = { default: mockWebExt } |
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,77 @@ | ||
const { fs, vol } = require('memfs') | ||
|
||
const { prepare } = require('../src') | ||
|
||
describe('prepare', () => { | ||
const mockOptions = { | ||
sourceDir: 'mock_dist', | ||
manifestPath: 'mock_manifest.json', | ||
} | ||
const defaultConfig = { | ||
nextRelease: { version: 'v3.2.1' }, | ||
logger: console, | ||
} | ||
|
||
beforeAll(() => { | ||
jest.spyOn(console, 'log') | ||
}) | ||
afterEach(() => { | ||
vol.reset() | ||
}) | ||
afterAll(() => { | ||
jest.restoreAllMocks() | ||
}) | ||
|
||
it('uses default options when nothing supplied', () => { | ||
vol.fromJSON({ 'dist/manifest.json': '{}' }) | ||
prepare({}, defaultConfig) | ||
expect(console.log).toHaveBeenCalledWith( | ||
'Wrote version %s to %s', | ||
defaultConfig.nextRelease.version, | ||
'dist/manifest.json', | ||
) | ||
}) | ||
|
||
it('uses supplied configuration options', () => { | ||
vol.fromJSON({ 'mock_dist/mock_manifest.json': '{}' }) | ||
prepare(mockOptions, defaultConfig) | ||
expect(console.log).toHaveBeenCalledWith( | ||
'Wrote version %s to %s', | ||
defaultConfig.nextRelease.version, | ||
'mock_dist/mock_manifest.json', | ||
) | ||
}) | ||
|
||
it('fails if cannot read manifest file', () => { | ||
expect(() => prepare(mockOptions, defaultConfig)).toThrowError( | ||
'Unable to read manifest.json file', | ||
) | ||
}) | ||
|
||
it('fails if cannot parse manifest file', () => { | ||
vol.fromJSON({ 'dist/manifest.json': 'this is not valid json' }) | ||
expect(() => prepare({}, defaultConfig)).toThrowError( | ||
'Failed to parse manifest.json', | ||
) | ||
}) | ||
|
||
it('fails if cannot update manifest file', () => { | ||
jest.spyOn(fs, 'readFileSync').mockImplementationOnce(() => '{}') | ||
expect(() => | ||
prepare({ sourceDir: 'sourceDir' }, defaultConfig), | ||
).toThrowError('Failed to write updated manifest.json') | ||
}) | ||
|
||
it.each([ | ||
[{}, 'dist/manifest.json'], | ||
[mockOptions, 'mock_dist/mock_manifest.json'], | ||
])('successfully updates manifest file', (options, manifestPath) => { | ||
vol.fromJSON({ [manifestPath]: '{}' }) | ||
prepare(options, defaultConfig) | ||
expect(JSON.parse(fs.readFileSync(manifestPath))).toEqual( | ||
expect.objectContaining({ | ||
version: 'v3.2.1', | ||
}), | ||
) | ||
}) | ||
}) |
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,60 @@ | ||
const { fs, vol } = require('memfs') | ||
const { default: webExt } = require('web-ext') | ||
|
||
const { publish } = require('../src') | ||
|
||
describe('publish', () => { | ||
const extensionId = '{01234567-abcd-6789-cdef-0123456789ef}' | ||
const targetXpi = 'target-extension.xpi' | ||
const mockOptions = { | ||
artifactsDir: 'mock_artifacts', | ||
manifestPath: 'mock_manifest.json', | ||
sourceDir: 'mock_source', | ||
} | ||
const completeOptions = { extensionId, targetXpi, ...mockOptions } | ||
|
||
beforeAll(() => { | ||
jest.spyOn(console, 'log') | ||
}) | ||
afterEach(() => { | ||
vol.reset() | ||
jest.clearAllMocks() | ||
}) | ||
afterAll(() => { | ||
jest.restoreAllMocks() | ||
}) | ||
|
||
it('fails if extensionId is not given', () => { | ||
return expect(publish(mockOptions)).rejects.toThrow( | ||
'extensionId is missing', | ||
) | ||
}) | ||
|
||
it('fails if targetXpi is not given', () => { | ||
return expect(publish(mockOptions)).rejects.toThrow( | ||
'targetXpi is missing', | ||
) | ||
}) | ||
|
||
it('raises error if signing unsuccessful', () => { | ||
webExt.cmd.sign.mockResolvedValueOnce({ success: false }) | ||
return expect(publish(completeOptions)).rejects.toThrow( | ||
'Signing the extension failed', | ||
) | ||
}) | ||
|
||
it('renames downloaded file to target xpi', async () => { | ||
const downloadedFile = 'mock_downloaded.xpi' | ||
vol.fromJSON({ | ||
[`${mockOptions.artifactsDir}/${downloadedFile}`]: 'some fake signed xpi', | ||
}) | ||
webExt.cmd.sign.mockResolvedValueOnce({ | ||
success: true, | ||
downloadedFiles: [downloadedFile], | ||
}) | ||
const targetXpiPath = `${mockOptions.artifactsDir}/${targetXpi}` | ||
expect(fs.existsSync(targetXpiPath)).toBe(false) | ||
await publish(completeOptions) | ||
expect(fs.existsSync(targetXpiPath)).toBe(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 |
---|---|---|
@@ -0,0 +1,2 @@ | ||
jest.mock('fs') | ||
jest.mock('web-ext') |
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,64 @@ | ||
const { vol } = require('memfs') | ||
const mockProps = require('jest-mock-props') | ||
|
||
const { verifyConditions } = require('../src') | ||
|
||
mockProps.extend(jest) | ||
|
||
describe('verifyConditions', () => { | ||
const firefoxApiKeySpy = jest.spyOnProp(process.env, 'FIREFOX_API_KEY') | ||
const firefoxSecretKeySpy = jest.spyOnProp( | ||
process.env, | ||
'FIREFOX_SECRET_KEY', | ||
) | ||
const extensionId = '{01234567-abcd-6789-cdef-0123456789ef}' | ||
const targetXpi = 'target-extension.xpi' | ||
|
||
beforeEach(() => { | ||
firefoxApiKeySpy.mockValueOnce('some-api-key') | ||
firefoxSecretKeySpy.mockValueOnce('shh-its-a-secret') | ||
}) | ||
afterEach(() => { | ||
jest.resetAllMocks() | ||
}) | ||
afterAll(() => { | ||
jest.restoreAllMocks() | ||
}) | ||
|
||
it('fails if FIREFOX_API_KEY is missing from env', () => { | ||
firefoxApiKeySpy.mockReset() | ||
expect(() => verifyConditions({ extensionId, targetXpi })).toThrow( | ||
'FIREFOX_API_KEY is missing', | ||
) | ||
}) | ||
|
||
it('fails if FIREFOX_SECRET_KEY is missing from env', () => { | ||
firefoxSecretKeySpy.mockReset() | ||
expect(() => verifyConditions({ extensionId, targetXpi })).toThrow( | ||
'FIREFOX_SECRET_KEY is missing', | ||
) | ||
}) | ||
|
||
it('fails if extensionId is missing from options', () => { | ||
expect(() => verifyConditions({ targetXpi })).toThrow( | ||
'No extensionId was specified', | ||
) | ||
}) | ||
|
||
it('fails if targetXpi is missing from options', () => { | ||
expect(() => verifyConditions({ extensionId })).toThrow( | ||
'No targetXpi was specified', | ||
) | ||
}) | ||
|
||
it('fails if manifest.json file does not exist', () => { | ||
expect(() => verifyConditions({ extensionId, targetXpi })).toThrow( | ||
'manifest.json was not found', | ||
) | ||
}) | ||
|
||
it('succeeds if all conditions are met', () => { | ||
vol.fromJSON({ 'dist/manifest.json': '{}' }) | ||
expect(() => verifyConditions({ extensionId, targetXpi })).not.toThrow() | ||
}) | ||
}) |
Oops, something went wrong.