From 71da77410252cce7dd956da48724f8a6ef005392 Mon Sep 17 00:00:00 2001 From: Joris Kraak Date: Fri, 10 Jul 2020 11:49:14 +0200 Subject: [PATCH] fix: handle function transforms when `typescript` is set Fixes #56. --- index.js | 4 ++-- test/unit/index_spec.js | 15 +++++++++++++++ 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/index.js b/index.js index d122ca2..758af10 100644 --- a/index.js +++ b/index.js @@ -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) { @@ -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'), { diff --git a/test/unit/index_spec.js b/test/unit/index_spec.js index 0d705cf..83adeb7 100644 --- a/test/unit/index_spec.js +++ b/test/unit/index_spec.js @@ -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()