Skip to content
This repository has been archived by the owner on Jan 31, 2023. It is now read-only.

Commit

Permalink
fix: Handle function transforms when typescript is set (#57)
Browse files Browse the repository at this point in the history
Fixes #56.
  • Loading branch information
bauglir authored Jul 14, 2020
1 parent 0b94fc5 commit fb2f417
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
4 changes: 2 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ const getBrowserifyOptions = async (entry, userBrowserifyOptions = {}, typescrip
}

const transform = browserifyOptions.transform
const hasTsifyTransform = transform.some(([name]) => name.includes('tsify'))
const hasTsifyTransform = transform.some((stage) => Array.isArray(stage) && stage[0].includes('tsify'))
const hastsifyPlugin = browserifyOptions.plugin.includes('tsify')

if (hasTsifyTransform || hastsifyPlugin) {
Expand All @@ -136,7 +136,7 @@ Please do one of the following:

browserifyOptions.extensions.push('.ts', '.tsx')
// remove babelify setting
browserifyOptions.transform = transform.filter(([name]) => !name.includes('babelify'))
browserifyOptions.transform = transform.filter((stage) => !Array.isArray(stage) || !stage[0].includes('babelify'))
// add typescript compiler
browserifyOptions.transform.push([
path.join(__dirname, './lib/simple_tsify'), {
Expand Down
15 changes: 15 additions & 0 deletions test/unit/index_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -380,6 +380,21 @@ describe('browserify preprocessor', function () {
})
})

// Regression test for cypress-io/cypress-browserify-preprocessor#56
it('handles transforms defined as functions', function () {
this.createWriteStreamApi.on.withArgs('finish').yields()

const transform = [() => { }, {}]

this.options.browserifyOptions = { transform }

return this.run().then(() => {
transform.forEach((stage, stageIndex) => {
expect(browserify.lastCall.args[0].transform[stageIndex]).to.eql(stage)
})
})
})

it('removes babelify transform', function () {
this.createWriteStreamApi.on.withArgs('finish').yields()

Expand Down

0 comments on commit fb2f417

Please sign in to comment.