Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Weirdness with snapshots #470

Closed
quantizor opened this issue Jun 4, 2021 · 2 comments
Closed

Weirdness with snapshots #470

quantizor opened this issue Jun 4, 2021 · 2 comments
Assignees

Comments

@quantizor
Copy link

quantizor commented Jun 4, 2021

It seems when using swc-node/jest that newlines are potentially being double escaped as they show up in snapshot output as raw characters where they were simply interpreted as newlines under the typical jest process.

        to: FAKE1-744-894-6541 x3436
    -   body: |-
    -     Thanks. We will text you when a dose is available in your area.
    -     Questions? hidrb.com/faq
    -     Share? hidrb.com/#share
    +   body: >-
    +     \n    Thanks. We will text you when a dose is available in your area.\n   
    +     Questions? hidrb.com/faq\n    Share? hidrb.com/#share\n  
      ↵
@mmkal
Copy link

mmkal commented Jun 4, 2021

Here's a minimal repro of this problem:

With ts-jest the following test passes:

import dedent from 'ts-dedent'

test('dedent', () => {
  const s = dedent`
    one
    two
      three
        four
      five
    six
  `

  expect(s).toMatchInlineSnapshot(`
"one
two
  three
    four
  five
six"
`)
})

failure with swc-jest:

  ● dedent

    expect(received).toMatchInlineSnapshot(snapshot)

    Snapshot name: `dedent 1`

    - Snapshot  - 6
    + Received  + 1

    - one
    - two
    -   three
    -     four
    -   five
    - six
    + \n    one\n    two\n      three\n        four\n      five\n    six\n  

      17 |   `
      18 |
    > 19 |   expect(s).toMatchInlineSnapshot(`
         |             ^
      20 | "one
      21 | two
      22 |   

Here are the jest.config.js setups used to reproduce this:

ts-jest:

module.exports = {
  preset: 'ts-jest',
  globals: {
    'ts-jest': {
      diagnostics: false,
      isolatedModules: true,
    },
  },
  testEnvironment: 'node',
  testRunner: 'jest-circus/runner',
  setupFilesAfterEnv: ['./scripts/jest-setup.js'],
  testRegex: /\.test\.ts$/.source,
}

@swc-node/jest:

module.exports = {
  transform: {
    '^.+\\.(t|j)sx?$': ['@swc-node/jest'],
  },
  testEnvironment: 'node',
  testRunner: 'jest-circus/runner',
  setupFilesAfterEnv: ['./scripts/jest-setup.js'],
  testRegex: /\.test\.ts$/.source,
}

@Brooooooklyn Brooooooklyn self-assigned this Jun 5, 2021
@Whoaa512
Copy link

Looks related to swc-project/swc#1681

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

4 participants