Skip to content

Commit

Permalink
feat: add inline-source-map for webpack
Browse files Browse the repository at this point in the history
Uses inline-source-map for webpack when running the tests. This will
then give accurate line numbers for failing tests.
  • Loading branch information
garrensmith authored and vmx committed Apr 5, 2018
1 parent 4785bce commit 1ff41e5
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/config/webpack/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,13 @@ function webpackConfig (env) {
} else {
environment.TEST_BROWSER_JS = JSON.stringify('')
}
const sourcemap = env === 'test' ? 'inline-source-map' : 'source-map'

This comment has been minimized.

Copy link
@achingbrain

achingbrain Apr 16, 2018

Member

I was just about to create a PR for this very issue. Can this be released please?

This comment has been minimized.

Copy link
@vmx

vmx Apr 16, 2018

Member

Done.


return merge(base, {
entry: [
entry
],
devtool: 'source-map',
devtool: sourcemap,
output: {
filename: path.basename(entry),
library: libraryName,
Expand Down
40 changes: 40 additions & 0 deletions test/config/webpack.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ const mock = require('mock-require')
describe('config - webpack', () => {
afterEach(() => {
mock.stop('../../src/utils')
mock.stop('../../src/config/user')
})

it('custom configs', () => {
Expand Down Expand Up @@ -52,4 +53,43 @@ describe('config - webpack', () => {
expect(conf).to.have.property('devtool', 'eval')
})
})

it('uses inline-source-map for test', () => {
mock('../../src/config/user', function () {
return {
webpack: {},
entry: ''
}
})
const config = mock.reRequire('../../src/config/webpack')
return config('test').then((webpack) => {
expect(webpack.devtool).to.equal('inline-source-map')
})
})

it('uses sourcemap for production', () => {
mock('../../src/config/user', function () {
return {
webpack: {},
entry: ''
}
})
const config = mock.reRequire('../../src/config/webpack')
return config('production').then((webpack) => {
expect(webpack.devtool).to.equal('source-map')
})
})

it('uses sourcemap as the default', () => {
mock('../../src/config/user', function () {
return {
webpack: {},
entry: ''
}
})
const config = mock.reRequire('../../src/config/webpack')
return config().then((webpack) => {
expect(webpack.devtool).to.equal('source-map')
})
})
})

0 comments on commit 1ff41e5

Please sign in to comment.