Skip to content

Test runner cannot find snapshot with \r in title #56836

@melusc

Description

@melusc

Version

23.7.0

Platform

- my PC: Microsoft Windows NT 10.0.26100.0 x64
- ubuntu-latest on GitHub Actions
- windows-latest on GitHub Actions

Subsystem

Test runner

What steps will reproduce the bug?

test.ts:

import {test} from 'node:test';

test('\r', t => {
	t.assert.snapshot({json: 'value'});
});
$ node --test-update-snapshots test.ts
$ node --test test.ts

How often does it reproduce? Is there a required condition?

Always

What is the expected behavior? Why is that the expected behavior?

It should be able to select the correct snapshot that it has just written.

What do you see instead?

✖ failing tests:

test at test.ts:3:1
 (2.8696ms)
 1' not found in '[...]\node-test-snapshot-cr\test.ts.snapshot.' Missing snapshots can be generated by rerunning the command with the --test-update-snapshots flag.
      at SnapshotFile.getSnapshot (node:internal/test_runner/snapshot:69:19)
      at TestContext.snapshotAssertion (node:internal/test_runner/snapshot:206:41)
      at assert.<computed> [as snapshot] (node:internal/test_runner/test:254:18)
      at TestContext.<anonymous> (file:///[...]/node-test-snapshot-cr/test.ts:4:11)
      at Test.runInAsyncScope (node:async_hooks:211:14)
      at Test.run (node:internal/test_runner/test:980:25)
      at Test.start (node:internal/test_runner/test:878:17)
      at startSubtestAfterBootstrap (node:internal/test_runner/harness:297:17) {
    code: 'ERR_INVALID_STATE',
    snapshot: '\r 1',
    filename: '[...]\\node-test-snapshot-cr\\test.ts.snapshot'
  }

Additional information

Metadata

Metadata

Assignees

No one assigned

    Labels

    test_runnerIssues and PRs related to the test runner subsystem.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions