-
Notifications
You must be signed in to change notification settings - Fork 77
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
jest refactor @gasket/plugin-manifest (#530)
- Loading branch information
1 parent
3b8eefb
commit 9d5b3f5
Showing
8 changed files
with
108 additions
and
128 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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 |
---|---|---|
@@ -1,72 +1,67 @@ | ||
const assume = require('assume'); | ||
const sinon = require('sinon'); | ||
const proxyquire = require('proxyquire'); | ||
const mockWriteFileStub = jest.fn(); | ||
const mockMkdirpStub = jest.fn(); | ||
|
||
describe('build', function () { | ||
const writeFileStub = sinon.stub(); | ||
const mkdirpStub = sinon.stub(); | ||
jest.mock('fs', () => ({ | ||
promises: { | ||
writeFile: mockWriteFileStub | ||
} | ||
})); | ||
jest.mock('mkdirp', () => mockMkdirpStub); | ||
|
||
const build = proxyquire('../lib/build', { | ||
fs: { | ||
promises: { | ||
writeFile: writeFileStub | ||
} | ||
}, | ||
mkdirp: mkdirpStub, | ||
replace: sinon.stub() | ||
}); | ||
const build = require('../lib/build'); | ||
|
||
describe('build', function () { | ||
let gasket; | ||
|
||
beforeEach(function () { | ||
gasket = { | ||
execWaterfall: sinon.stub().resolves([]), | ||
execWaterfall: jest.fn().mockResolvedValue([]), | ||
config: { | ||
root: 'test', | ||
manifest: { | ||
staticOutput: '/custom/manifest.json' | ||
} | ||
}, | ||
logger: { | ||
debug: sinon.stub(), | ||
error: sinon.stub(), | ||
log: sinon.stub() | ||
debug: jest.fn(), | ||
error: jest.fn(), | ||
log: jest.fn() | ||
} | ||
}; | ||
}); | ||
|
||
afterEach(function () { | ||
sinon.reset(); | ||
jest.clearAllMocks(); | ||
}); | ||
|
||
it('is a function', function () { | ||
assume(build).is.a('asyncfunction'); | ||
assume(build).has.length(1); | ||
expect(typeof build).toBe('function'); | ||
expect(build).toHaveLength(1); | ||
}); | ||
|
||
it('skips logic when staticOutput config is not set', async function () { | ||
gasket.config.manifest = {}; | ||
await build(gasket); | ||
|
||
assume(mkdirpStub.called).false(); | ||
expect(mockMkdirpStub).not.toHaveBeenCalled(); | ||
}); | ||
|
||
it('creates custom output directory', async function () { | ||
gasket.config.manifest.staticOutput = '/super/cool/custom/path/manifest.json'; | ||
await build(gasket); | ||
assume(mkdirpStub.calledOnce).true(); | ||
assume(mkdirpStub.args[0][0]).eqls('/super/cool/custom/path/'); | ||
expect(mockMkdirpStub).toHaveBeenCalled(); | ||
expect(mockMkdirpStub.mock.calls[0][0]).toEqual('/super/cool/custom/path/'); | ||
}); | ||
|
||
it('writes manifest to specified path', async function () { | ||
await build(gasket); | ||
assume(writeFileStub.calledOnce).true(); | ||
assume(writeFileStub.args[0]).eqls(['/custom/manifest.json', '[]', 'utf-8']); | ||
expect(mockWriteFileStub.mock.calls.length).toBe(1); | ||
expect(mockWriteFileStub.mock.calls[0]).toEqual(['/custom/manifest.json', '[]', 'utf-8']); | ||
}); | ||
|
||
it('logs completion message', async function () { | ||
await build(gasket); | ||
assume(gasket.logger.log.calledOnce).true(); | ||
assume(gasket.logger.log.args[0][0]).includes('custom/manifest.json).'); | ||
expect(gasket.logger.log.mock.calls.length).toBe(1); | ||
expect(gasket.logger.log.mock.calls[0][0]).toContain('custom/manifest.json).'); | ||
}); | ||
}); |
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
Oops, something went wrong.