Skip to content

Instantly share code, notes, and snippets.

@DSchau
Created November 19, 2018 17:39
Show Gist options
  • Select an option

  • Save DSchau/5e828544207ab8173d3aef87a7fa7b33 to your computer and use it in GitHub Desktop.

Select an option

Save DSchau/5e828544207ab8173d3aef87a7fa7b33 to your computer and use it in GitHub Desktop.
Unit test for plugin functionality
jest.mock('../local-eslint-config-finder', () => jest.fn())
jest.mock('../eslint-config', () => jest.fn())
jest.mock('../api-runner-node', () => jest.fn())
jest.mock('../../redux', () => ({
store: {
dispatch: jest.fn(),
getState: jest.fn().mockImplementation(() => ({
program: {
extensions: []
}
}))
}
}))
const { DefinePlugin } = require(`webpack`)
const webpackConfig = require(`../webpack.config`)
const { store } = require(`../../redux`)
const setup = async ({
suppliedStage
} = {}) => {
const program = {}
const directory = process.cwd()
await webpackConfig(program, directory, suppliedStage || 'develop')
return store.dispatch.mock.calls[0][0].payload
}
test(`it does not include entire process.env object`, async () => {
const config = await setup()
const definePlugin = config.plugins.find(plugin => plugin instanceof DefinePlugin)
expect(definePlugin.definitions).toEqual(expect.objectContaining({
'process.env': '{}'
}))
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment