Skip to content

Commit 76fa750

Browse files
Add webpack 5 support; fixes #92 (#97)
* Add webpack 5 support; fixes #92 * Re-record test fixtures; test both versions 4 and 5 to ensure backwards compatibility Co-authored-by: Zach Schneider <zach@schneider.dev>
1 parent 0d3794d commit 76fa750

168 files changed

Lines changed: 1633 additions & 2100 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.tav.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
webpack-4:
2+
name: webpack
3+
versions: 4.41.6
4+
commands: jest
5+
6+
webpack-5:
7+
name: webpack
8+
versions: 5.0.0-beta.13
9+
commands: jest

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@ node_js:
33
- "node"
44
script:
55
- yarn lint
6-
- yarn test
6+
- yarn test:tav

package-scripts.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,15 @@ module.exports = {
2727
'test:record': {
2828
description: 'Run tests + regenerate fixtures with real Sentry instance',
2929
script: 'rm ./test/fixtures/replayer/* && VCR_MODE=record jest'
30+
},
31+
'test:tav': {
32+
description: 'Run tests against all supported major versions',
33+
script: 'VCR_MODE=playback tav'
34+
},
35+
'test:tav:record': {
36+
description:
37+
'Run tests against all supported major versions + regenerate fixtures',
38+
script: 'VCR_MODE=record tav'
3039
}
3140
}
3241
}

package.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121
"lint": "nps lint",
2222
"test": "nps test",
2323
"test:record": "nps test:record",
24+
"test:tav": "nps test:tav",
25+
"test:tav:record": "nps test:tav:record",
2426
"validate": "nps validate",
2527
"prepublish": "nps prepublish",
2628
"precommit": "opt --in pre-commit --exec \"nps format lint\"",
@@ -62,7 +64,8 @@
6264
"prettier": "^1.11.1",
6365
"prettier-eslint-cli": "^4.7.1",
6466
"replayer": "^2.2.3",
65-
"webpack": "^4.5.0"
67+
"test-all-versions": "^4.1.1",
68+
"webpack": "^5.0.0-beta.13"
6669
},
6770
"peerDependencies": {
6871
"webpack": "^4 || ^5.0.0-alpha.11"

src/index.js

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import request from 'request-promise'
22
import fs from 'fs'
3+
import path from 'path'
34
import PromisePool from 'es6-promise-pool'
45

56
const BASE_SENTRY_URL = 'https://sentry.io/api/0'
@@ -146,11 +147,19 @@ module.exports = class SentryPlugin {
146147
}
147148
}
148149

150+
// eslint-disable-next-line class-methods-use-this
151+
getAssetPath(compilation, name) {
152+
return path.join(
153+
compilation.getPath(compilation.compiler.outputPath),
154+
name.split('?')[0]
155+
)
156+
}
157+
149158
getFiles(compilation) {
150159
return Object.keys(compilation.assets)
151160
.map((name) => {
152161
if (this.isIncludeOrExclude(name)) {
153-
return { name, filePath: compilation.assets[name].existsAt }
162+
return { name, filePath: this.getAssetPath(compilation, name) }
154163
}
155164
return null
156165
})
@@ -238,7 +247,7 @@ module.exports = class SentryPlugin {
238247
Object.keys(stats.compilation.assets)
239248
.filter(name => this.deleteRegex.test(name))
240249
.forEach((name) => {
241-
const filePath = stats.compilation.assets[name].existsAt
250+
const filePath = this.getAssetPath(stats.compilation, name)
242251
if (filePath) {
243252
fs.unlinkSync(filePath)
244253
}

test/errors.test.js

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { expectWebpackError } from './helpers/assertion'
12
import { createWebpackConfig, runWebpack } from './helpers/webpack'
23

34
jest.mock('request-promise')
@@ -6,7 +7,8 @@ it('adds error if Sentry organization slug is missing', () =>
67
runWebpack(createWebpackConfig({ organization: null })).catch(
78
({ errors }) => {
89
expect(errors).toHaveLength(1)
9-
expect(errors[0]).toEqual(
10+
expectWebpackError(
11+
errors[0],
1012
'Sentry Plugin: Error: Must provide organization'
1113
)
1214
}
@@ -15,19 +17,20 @@ it('adds error if Sentry organization slug is missing', () =>
1517
it('adds error if Sentry project name is missing', () =>
1618
runWebpack(createWebpackConfig({ project: null })).catch(({ errors }) => {
1719
expect(errors).toHaveLength(1)
18-
expect(errors[0]).toEqual('Sentry Plugin: Error: Must provide project')
20+
expectWebpackError(errors[0], 'Sentry Plugin: Error: Must provide project')
1921
}))
2022

2123
it('adds error if Sentry api key is missing', () =>
2224
runWebpack(createWebpackConfig({ apiKey: null })).catch(({ errors }) => {
2325
expect(errors).toHaveLength(1)
24-
expect(errors[0]).toEqual('Sentry Plugin: Error: Must provide api key')
26+
expectWebpackError(errors[0], 'Sentry Plugin: Error: Must provide api key')
2527
}))
2628

2729
it('adds error if release version is missing', () =>
2830
runWebpack(createWebpackConfig()).catch(({ errors }) => {
2931
expect(errors).toHaveLength(1)
30-
expect(errors[0]).toEqual(
32+
expectWebpackError(
33+
errors[0],
3134
'Sentry Plugin: Error: Must provide release version'
3235
)
3336
}))
@@ -36,14 +39,20 @@ it('adds release error to compilation', () =>
3639
runWebpack(createWebpackConfig({ release: 'bad-release' })).catch(
3740
({ errors }) => {
3841
expect(errors).toHaveLength(1)
39-
expect(errors[0]).toEqual('Sentry Plugin: Error: Release request error')
42+
expectWebpackError(
43+
errors[0],
44+
'Sentry Plugin: Error: Release request error'
45+
)
4046
}
4147
))
4248

4349
it('adds upload error to compilation', () =>
4450
runWebpack(createWebpackConfig({ release: 'bad-upload' })).catch(
4551
({ errors }) => {
4652
expect(errors).toHaveLength(1)
47-
expect(errors[0]).toEqual('Sentry Plugin: Error: Upload request error')
53+
expectWebpackError(
54+
errors[0],
55+
'Sentry Plugin: Error: Upload request error'
56+
)
4857
}
4958
))

test/fixtures/replayer/0024538aa3f548d991123198a677df88

Lines changed: 0 additions & 1 deletion
This file was deleted.

test/fixtures/replayer/0024538aa3f548d991123198a677df88.headers

Lines changed: 0 additions & 29 deletions
This file was deleted.

test/fixtures/replayer/0393df35ada1d3f402d50686d9e6e9bc

Whitespace-only changes.

test/fixtures/replayer/0393df35ada1d3f402d50686d9e6e9bc.headers

Lines changed: 0 additions & 27 deletions
This file was deleted.

0 commit comments

Comments
 (0)