-
Notifications
You must be signed in to change notification settings - Fork 289
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(jest-environment-puppeteer): support custom config
Closes #19
- Loading branch information
Showing
5 changed files
with
91 additions
and
12 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
5 changes: 5 additions & 0 deletions
5
packages/jest-environment-puppeteer/tests/__fixtures__/customConfig.js
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,5 @@ | ||
module.exports = { | ||
server: { | ||
command: 'yarn babel-node src/server/main.js', | ||
}, | ||
} |
61 changes: 61 additions & 0 deletions
61
packages/jest-environment-puppeteer/tests/readConfig.test.js
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,61 @@ | ||
import fs from 'fs' | ||
import path from 'path' | ||
import readConfig from '../src/readConfig' | ||
|
||
jest.mock('fs') | ||
|
||
function mockExists(value) { | ||
fs.exists.mockImplementation((path, callback) => callback(null, value)) | ||
} | ||
|
||
describe('readConfig', () => { | ||
describe('with custom config path', () => { | ||
beforeEach(() => { | ||
process.env.JEST_PUPPETEER_CONFIG = 'nop.js' | ||
}) | ||
|
||
it('should return an error if not found', async () => { | ||
process.env.JEST_PUPPETEER_CONFIG = 'nop.js' | ||
expect.assertions(1) | ||
mockExists(false) | ||
try { | ||
await readConfig() | ||
} catch (error) { | ||
expect(error.message).toBe( | ||
"Error: Can't find a root directory while resolving a config file path.\nProvided path to resolve: nop.js", | ||
) | ||
} | ||
}) | ||
|
||
it('should return custom config', async () => { | ||
process.env.JEST_PUPPETEER_CONFIG = path.resolve( | ||
__dirname, | ||
'__fixtures__/customConfig.js', | ||
) | ||
mockExists(true) | ||
const config = await readConfig() | ||
expect(config).toEqual({ | ||
launch: {}, | ||
server: { command: 'yarn babel-node src/server/main.js' }, | ||
}) | ||
}) | ||
}) | ||
|
||
describe('with default config path', () => { | ||
beforeEach(() => { | ||
process.env.JEST_PUPPETEER_CONFIG = '' | ||
}) | ||
|
||
it('should return custom config', async () => { | ||
mockExists(true) | ||
const config = await readConfig() | ||
expect(config.server).toBeDefined() | ||
}) | ||
|
||
it('should return default config if not found', async () => { | ||
mockExists(false) | ||
const config = await readConfig() | ||
expect(config).toEqual({ launch: {} }) | ||
}) | ||
}) | ||
}) |