Skip to content
This repository has been archived by the owner on Oct 1, 2020. It is now read-only.

Commit

Permalink
fix: Ensure that the webpack output filename ends with .js. (#73)
Browse files Browse the repository at this point in the history
This ensures that the Webpack SourceMapDevToolPlugin can handle the file, even when it has been originally no javascript file (e.g. .ts or .feature).

Co-authored-by: Chris Breiding <chrisbreiding@users.noreply.github.com>
  • Loading branch information
jp7677 and chrisbreiding authored Apr 13, 2020
1 parent dd2575b commit a6baf1f
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
4 changes: 3 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,9 @@ const preprocessor = (options = {}) => {
// we're provided a default output path that lives alongside Cypress's
// app data files so we don't have to worry about where to put the bundled
// file on disk
const outputPath = file.outputPath
const outputPath = path.extname(file.outputPath) === '.js'
? file.outputPath
: `${file.outputPath}.js`

// we need to set entry and output
webpackOptions = Object.assign(webpackOptions, {
Expand Down
19 changes: 19 additions & 0 deletions test/unit/index.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,17 @@ describe('webpack preprocessor', function () {
})
})

it('adds .js extension to filename when the originating file had been no javascript file', function () {
this.file.outputPath = 'output/output.ts'

return this.run().then(() => {
expect(webpack.lastCall.args[0].output).to.eql({
path: 'output',
filename: 'output.ts.js',
})
})
})

it('enables inline source maps', function () {
return this.run().then(() => {
expect(webpack.lastCall.args[0].devtool).to.equal('inline-source-map')
Expand Down Expand Up @@ -179,6 +190,14 @@ describe('webpack preprocessor', function () {
})
})

it('adds .js extension and resolves with that output path when the originating file had been no javascript file', function () {
this.file.outputPath = 'output/output.ts'

return this.run().then((outputPath) => {
expect(outputPath).to.be.equal('output/output.ts.js')
})
})

it('emits "rerun" when shouldWatch is true and there is an update', function () {
this.file.shouldWatch = true
this.compilerApi.watch.yields(null, this.statsApi)
Expand Down

0 comments on commit a6baf1f

Please sign in to comment.