Skip to content

Commit

Permalink
fix: support multiple imports of one module with multiple lines (#30314)
Browse files Browse the repository at this point in the history
e.g.
```
import {
  a,
  b,
  c,
} from 'x';
```

chore: remove unnecessary deep equal

Co-authored-by: Bill Glesias <[email protected]>
  • Loading branch information
wenfw and AtofStryker authored Nov 22, 2024
1 parent d6d5c6d commit 12df40e
Show file tree
Hide file tree
Showing 4 changed files with 79 additions and 3 deletions.
9 changes: 9 additions & 0 deletions cli/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,13 @@
<!-- See the ../guides/writing-the-cypress-changelog.md for details on writing the changelog. -->

## 13.16.1

_Released 11/26/2024 (PENDING)_

**Bugfixes:**

- Support multiple imports of one module with multiple lines. Addressed in [#30314](https://github.com/cypress-io/cypress/pull/30314).

## 13.16.0

_Released 11/19/2024_
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@ export const export1 = 'export1'

export const export2 = 'export2'

export const export3 = 'export3'

export const export4 = 'export4'

export const export5 = 'export5'

// @ts-expect-error
window.sideEffect = 'Side Effect'

Expand Down
65 changes: 63 additions & 2 deletions npm/vite-plugin-cypress-esm/cypress/component/importSyntax.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,17 @@ import { default as alias } from './fixtures/kitchenSink'
import defaultExport2, { export2 } from './fixtures/kitchenSink'
import defaultExport3, * as name2 from './fixtures/kitchenSink'
import { export1 as e1, export2 as e2 } from './fixtures/kitchenSink'
import {
export3,
export4,
} from './fixtures/kitchenSink'
import {
export3 as alias3,
export4 as alias4,
} from './fixtures/kitchenSink'
import defaultExport4, {
export5,
} from './fixtures/kitchenSink'
import './fixtures/kitchenSink'

// Examples for all syntax
Expand All @@ -19,6 +30,9 @@ describe('supports every combination of import syntax in a single file', () => {
expect(defaultExport1).to.deep.eq({
export1: 'export1',
export2: 'export2',
export3: 'export3',
export4: 'export4',
export5: 'export5',
default: {
export1: 'export1',
export2: 'export2',
Expand All @@ -30,6 +44,9 @@ describe('supports every combination of import syntax in a single file', () => {
expect(name1).to.deep.eq({
export1: 'export1',
export2: 'export2',
export3: 'export3',
export4: 'export4',
export5: 'export5',
default: {
export1: 'export1',
export2: 'export2',
Expand All @@ -38,7 +55,7 @@ describe('supports every combination of import syntax in a single file', () => {
})

it('Import { export1 } from "./kitchenSink"', () => {
expect(export1).to.deep.eq(export1)
expect(export1).to.eq('export1')
})

it('Import { export1 as alias1 } from "./kitchenSink"', () => {
Expand All @@ -56,19 +73,25 @@ describe('supports every combination of import syntax in a single file', () => {
expect(defaultExport2).to.deep.eq({
export1: 'export1',
export2: 'export2',
export3: 'export3',
export4: 'export4',
export5: 'export5',
default: {
export1: 'export1',
export2: 'export2',
},
})

expect(export2).to.eq(export2)
expect(export2).to.eq('export2')
})

it('Import defaultExport3, * as name2 from "./kitchenSink"', () => {
expect(defaultExport3).to.deep.eq({
export1: 'export1',
export2: 'export2',
export3: 'export3',
export4: 'export4',
export5: 'export5',
default: {
export1: 'export1',
export2: 'export2',
Expand All @@ -80,6 +103,9 @@ describe('supports every combination of import syntax in a single file', () => {
expect(name2).to.deep.eq({
export1: 'export1',
export2: 'export2',
export3: 'export3',
export4: 'export4',
export5: 'export5',
default: {
export1: 'export1',
export2: 'export2',
Expand All @@ -92,6 +118,41 @@ describe('supports every combination of import syntax in a single file', () => {
expect(e2).to.deep.eq(export2)
})

it(`import {
export3,
export4,
} from './fixtures/kitchenSink'`, () => {
expect(export3).to.deep.eq('export3')
expect(export4).to.deep.eq('export4')
})

it(`import {
export3 as alias3,
export4 as alias4,
} from './fixtures/kitchenSink'`, () => {
expect(alias3).to.deep.eq(export3)
expect(alias4).to.deep.eq(export4)
})

it(`import defaultExport4, {
export5,
} from './fixtures/kitchenSink'`, () => {
console.log(defaultExport4)
expect(defaultExport4).to.deep.eq({
export1: 'export1',
export2: 'export2',
export3: 'export3',
export4: 'export4',
export5: 'export5',
default: {
export1: 'export1',
export2: 'export2',
},
})

expect(export5).to.eq('export5')
})

it('Import "./kitchenSink"', () => {
// @ts-expect-error
expect(window.sideEffect).to.eq('Side Effect')
Expand Down
2 changes: 1 addition & 1 deletion npm/vite-plugin-cypress-esm/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ export const CypressEsm = (options?: CypressEsmOptions): Plugin => {

// Ensure import comes at start of line *or* is prefixed by a space so we don't capture things like
// `Refresh.__hmr_import('')
const importRegex = /(?<=^|\s)import (.+?) from ['"](.*?)['"]/g
const importRegex = /(?<=^|\s)import ([^;'"]+?) from ['"](.*?)['"]/g

return code.replace(
importRegex,
Expand Down

5 comments on commit 12df40e

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on 12df40e Nov 22, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Circle has built the linux x64 version of the Test Runner.

Learn more about this pre-release build at https://on.cypress.io/advanced-installation#Install-pre-release-version

Run this command to install the pre-release locally:

npm install https://cdn.cypress.io/beta/npm/13.16.1/linux-x64/develop-12df40ed8c1101c5c4053a1fe63c06fcd2809bc7/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on 12df40e Nov 22, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Circle has built the linux arm64 version of the Test Runner.

Learn more about this pre-release build at https://on.cypress.io/advanced-installation#Install-pre-release-version

Run this command to install the pre-release locally:

npm install https://cdn.cypress.io/beta/npm/13.16.1/linux-arm64/develop-12df40ed8c1101c5c4053a1fe63c06fcd2809bc7/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on 12df40e Nov 22, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Circle has built the win32 x64 version of the Test Runner.

Learn more about this pre-release build at https://on.cypress.io/advanced-installation#Install-pre-release-version

Run this command to install the pre-release locally:

npm install https://cdn.cypress.io/beta/npm/13.16.1/win32-x64/develop-12df40ed8c1101c5c4053a1fe63c06fcd2809bc7/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on 12df40e Nov 22, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Circle has built the darwin arm64 version of the Test Runner.

Learn more about this pre-release build at https://on.cypress.io/advanced-installation#Install-pre-release-version

Run this command to install the pre-release locally:

npm install https://cdn.cypress.io/beta/npm/13.16.1/darwin-arm64/develop-12df40ed8c1101c5c4053a1fe63c06fcd2809bc7/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on 12df40e Nov 22, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Circle has built the darwin x64 version of the Test Runner.

Learn more about this pre-release build at https://on.cypress.io/advanced-installation#Install-pre-release-version

Run this command to install the pre-release locally:

npm install https://cdn.cypress.io/beta/npm/13.16.1/darwin-x64/develop-12df40ed8c1101c5c4053a1fe63c06fcd2809bc7/cypress.tgz

Please sign in to comment.