From 3ea9b7eb37aa5021de3b31f268c1056221af57df Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Iiro=20J=C3=A4ppinen?= Date: Mon, 21 Nov 2022 09:49:01 +0200 Subject: [PATCH] test: update Jest snapshot format --- test/integration/git-lock-file.test.js | 22 ++--- test/integration/gitWorkFlow.test.js | 24 ++--- test/integration/merge-conflict.test.js | 18 ++-- test/integration/no-stash.test.js | 2 +- test/unit/execGit.spec.js | 2 +- test/unit/index2.spec.js | 16 ++-- test/unit/loadConfig.spec.js | 20 ++-- test/unit/resolveTaskFn.spec.js | 24 ++--- test/unit/resolveTaskFn.unmocked.spec.js | 2 +- test/unit/runAll.spec.js | 112 +++++++++++------------ 10 files changed, 121 insertions(+), 121 deletions(-) diff --git a/test/integration/git-lock-file.test.js b/test/integration/git-lock-file.test.js index 307fdd4e8..f1dd3f8bd 100644 --- a/test/integration/git-lock-file.test.js +++ b/test/integration/git-lock-file.test.js @@ -47,17 +47,17 @@ describe('lint-staged', () => { // But local modifications are gone expect(await execGit(['diff'])).not.toEqual(diff) expect(await execGit(['diff'])).toMatchInlineSnapshot(` - "diff --git a/test.js b/test.js - index 1eff6a0..8baadc8 100644 - --- a/test.js - +++ b/test.js - @@ -1,3 +1,3 @@ - module.exports = { - - 'foo': 'bar' - -} - + foo: \\"bar\\", - +};" - `) + "diff --git a/test.js b/test.js + index 1eff6a0..8baadc8 100644 + --- a/test.js + +++ b/test.js + @@ -1,3 +1,3 @@ + module.exports = { + - 'foo': 'bar' + -} + + foo: "bar", + +};" + `) expect(await readFile('test.js')).not.toEqual(uglyJS + appended) expect(await readFile('test.js')).toEqual(prettyJS) diff --git a/test/integration/gitWorkFlow.test.js b/test/integration/gitWorkFlow.test.js index 40873432c..63a3e3f59 100644 --- a/test/integration/gitWorkFlow.test.js +++ b/test/integration/gitWorkFlow.test.js @@ -39,18 +39,18 @@ describe('gitWorkflow', () => { `"test"` ) expect(ctx).toMatchInlineSnapshot(` - Object { + { "errors": Set { Symbol(GitError), }, "events": EventEmitter { - "_events": Object {}, + "_events": {}, "_eventsCount": 0, "_maxListeners": undefined, Symbol(kCapture): false, }, "hasPartiallyStagedFiles": true, - "output": Array [], + "output": [], "quiet": false, "shouldBackup": null, } @@ -70,19 +70,19 @@ describe('gitWorkflow', () => { `"lint-staged automatic backup is missing!"` ) expect(ctx).toMatchInlineSnapshot(` - Object { + { "errors": Set { Symbol(GetBackupStashError), Symbol(GitError), }, "events": EventEmitter { - "_events": Object {}, + "_events": {}, "_eventsCount": 0, "_maxListeners": undefined, Symbol(kCapture): false, }, "hasPartiallyStagedFiles": null, - "output": Array [], + "output": [], "quiet": false, "shouldBackup": null, } @@ -144,19 +144,19 @@ describe('gitWorkflow', () => { `pathspec '${totallyRandom}' did not match any file(s) known to git` ) expect(ctx).toMatchInlineSnapshot(` - Object { + { "errors": Set { Symbol(GitError), Symbol(HideUnstagedChangesError), }, "events": EventEmitter { - "_events": Object {}, + "_events": {}, "_eventsCount": 0, "_maxListeners": undefined, Symbol(kCapture): false, }, "hasPartiallyStagedFiles": null, - "output": Array [], + "output": [], "quiet": false, "shouldBackup": null, } @@ -198,19 +198,19 @@ describe('gitWorkflow', () => { `"Merge state could not be restored due to an error!"` ) expect(ctx).toMatchInlineSnapshot(` - Object { + { "errors": Set { Symbol(GitError), Symbol(RestoreMergeStatusError), }, "events": EventEmitter { - "_events": Object {}, + "_events": {}, "_eventsCount": 0, "_maxListeners": undefined, Symbol(kCapture): false, }, "hasPartiallyStagedFiles": null, - "output": Array [], + "output": [], "quiet": false, "shouldBackup": null, } diff --git a/test/integration/merge-conflict.test.js b/test/integration/merge-conflict.test.js index fe173686f..63c3cf3b4 100644 --- a/test/integration/merge-conflict.test.js +++ b/test/integration/merge-conflict.test.js @@ -50,13 +50,13 @@ describe('lint-staged', () => { await expect(execGit(['merge', 'branch-b'])).rejects.toThrowError('Merge conflict in test.js') expect(await readFile('test.js')).toMatchInlineSnapshot(` - "<<<<<<< HEAD - module.exports = \\"foo\\"; - ======= - module.exports = \\"bar\\"; - >>>>>>> branch-b - " - `) + "<<<<<<< HEAD + module.exports = "foo"; + ======= + module.exports = "bar"; + >>>>>>> branch-b + " + `) // Fix conflict and commit using lint-staged await writeFile('test.js', fileInBranchB) @@ -115,9 +115,9 @@ describe('lint-staged', () => { expect(await readFile('test.js')).toMatchInlineSnapshot(` "<<<<<<< HEAD - module.exports = \\"foo\\"; + module.exports = "foo"; ======= - module.exports = \\"bar\\"; + module.exports = "bar"; >>>>>>> branch-b " `) diff --git a/test/integration/no-stash.test.js b/test/integration/no-stash.test.js index 7a26ce471..769efbb8d 100644 --- a/test/integration/no-stash.test.js +++ b/test/integration/no-stash.test.js @@ -66,7 +66,7 @@ describe('lint-staged', () => { expect(await readFile('test.js')).toMatchInlineSnapshot(` "<<<<<<< ours module.exports = { - foo: \\"bar\\", + foo: "bar", }; ======= const obj = { diff --git a/test/unit/execGit.spec.js b/test/unit/execGit.spec.js index a3a8f038a..8b49dca50 100644 --- a/test/unit/execGit.spec.js +++ b/test/unit/execGit.spec.js @@ -12,7 +12,7 @@ jest.mock('execa', () => ({ test('GIT_GLOBAL_OPTIONS', () => { expect(GIT_GLOBAL_OPTIONS).toMatchInlineSnapshot(` - Array [ + [ "-c", "submodule.recurse=false", ] diff --git a/test/unit/index2.spec.js b/test/unit/index2.spec.js index 2c88c1708..ff195bb12 100644 --- a/test/unit/index2.spec.js +++ b/test/unit/index2.spec.js @@ -46,17 +46,17 @@ describe('lintStaged', () => { await lintStaged({ configPath: MOCK_CONFIG_FILE, quiet: true }, makeConsoleMock()) expect(Listr.mock.calls[0][1]).toMatchInlineSnapshot(` - Object { - "ctx": Object { + { + "ctx": { "errors": Set {}, "events": EventEmitter { - "_events": Object {}, + "_events": {}, "_eventsCount": 0, "_maxListeners": undefined, Symbol(kCapture): false, }, "hasPartiallyStagedFiles": null, - "output": Array [], + "output": [], "quiet": true, "shouldBackup": true, }, @@ -79,17 +79,17 @@ describe('lintStaged', () => { ) expect(Listr.mock.calls[0][1]).toMatchInlineSnapshot(` - Object { - "ctx": Object { + { + "ctx": { "errors": Set {}, "events": EventEmitter { - "_events": Object {}, + "_events": {}, "_eventsCount": 0, "_maxListeners": undefined, Symbol(kCapture): false, }, "hasPartiallyStagedFiles": null, - "output": Array [], + "output": [], "quiet": false, "shouldBackup": true, }, diff --git a/test/unit/loadConfig.spec.js b/test/unit/loadConfig.spec.js index b2b3f523c..7dfbb7b52 100644 --- a/test/unit/loadConfig.spec.js +++ b/test/unit/loadConfig.spec.js @@ -39,7 +39,7 @@ describe('loadConfig', () => { ) expect(config).toMatchInlineSnapshot(` - Object { + { "*": "mytask", } `) @@ -54,7 +54,7 @@ describe('loadConfig', () => { ) expect(config).toMatchInlineSnapshot(` - Object { + { "*": "mytask", } `) @@ -69,7 +69,7 @@ describe('loadConfig', () => { ) expect(config).toMatchInlineSnapshot(` - Object { + { "*.css": [Function], "*.js": [Function], } @@ -85,7 +85,7 @@ describe('loadConfig', () => { ) expect(config).toMatchInlineSnapshot(` - Object { + { "*.css": [Function], "*.js": [Function], } @@ -101,7 +101,7 @@ describe('loadConfig', () => { ) expect(config).toMatchInlineSnapshot(` - Object { + { "*": "mytask", } `) @@ -120,7 +120,7 @@ describe('loadConfig', () => { ) expect(config).toMatchInlineSnapshot(` - Object { + { "*": "mytask", } `) @@ -139,7 +139,7 @@ describe('loadConfig', () => { ) expect(config).toMatchInlineSnapshot(` - Object { + { "*": "mytask", } `) @@ -156,7 +156,7 @@ describe('loadConfig', () => { ) expect(config).toMatchInlineSnapshot(` - Object { + { "*": "mytask", } `) @@ -167,7 +167,7 @@ describe('loadConfig', () => { const result = await loadConfig({ cwd: '/' }) - expect(result).toMatchInlineSnapshot(`Object {}`) + expect(result).toMatchInlineSnapshot(`{}`) }) it('should return empty object when explicit config file is not found', async () => { @@ -175,6 +175,6 @@ describe('loadConfig', () => { const result = await loadConfig({ configPath: 'fake-config-file.yml' }, logger) - expect(result).toMatchInlineSnapshot(`Object {}`) + expect(result).toMatchInlineSnapshot(`{}`) }) }) diff --git a/test/unit/resolveTaskFn.spec.js b/test/unit/resolveTaskFn.spec.js index 1aeb64ed8..7800fb1ee 100644 --- a/test/unit/resolveTaskFn.spec.js +++ b/test/unit/resolveTaskFn.spec.js @@ -242,16 +242,16 @@ describe('resolveTaskFn', () => { const context = getInitialState() await expect(taskFn(context)).resolves.toMatchInlineSnapshot(`undefined`) expect(context).toMatchInlineSnapshot(` - Object { + { "errors": Set {}, "events": EventEmitter { - "_events": Object {}, + "_events": {}, "_eventsCount": 0, "_maxListeners": undefined, Symbol(kCapture): false, }, "hasPartiallyStagedFiles": null, - "output": Array [], + "output": [], "quiet": false, "shouldBackup": null, } @@ -274,16 +274,16 @@ describe('resolveTaskFn', () => { const context = getInitialState() await expect(taskFn(context)).resolves.toMatchInlineSnapshot(`undefined`) expect(context).toMatchInlineSnapshot(` - Object { + { "errors": Set {}, "events": EventEmitter { - "_events": Object {}, + "_events": {}, "_eventsCount": 0, "_maxListeners": undefined, Symbol(kCapture): false, }, "hasPartiallyStagedFiles": null, - "output": Array [ + "output": [ " → mock cmd: Mock success", @@ -310,18 +310,18 @@ describe('resolveTaskFn', () => { const context = getInitialState({ quiet: true }) await expect(taskFn(context)).rejects.toThrowErrorMatchingInlineSnapshot(`"mock cmd [1]"`) expect(context).toMatchInlineSnapshot(` - Object { + { "errors": Set { Symbol(TaskError), }, "events": EventEmitter { - "_events": Object {}, + "_events": {}, "_eventsCount": 0, "_maxListeners": undefined, Symbol(kCapture): false, }, "hasPartiallyStagedFiles": null, - "output": Array [ + "output": [ "stderr", ], "quiet": true, @@ -346,18 +346,18 @@ describe('resolveTaskFn', () => { const context = getInitialState({ quiet: true }) await expect(taskFn(context)).rejects.toThrowErrorMatchingInlineSnapshot(`"mock cmd [1]"`) expect(context).toMatchInlineSnapshot(` - Object { + { "errors": Set { Symbol(TaskError), }, "events": EventEmitter { - "_events": Object {}, + "_events": {}, "_eventsCount": 0, "_maxListeners": undefined, Symbol(kCapture): false, }, "hasPartiallyStagedFiles": null, - "output": Array [], + "output": [], "quiet": true, "shouldBackup": null, } diff --git a/test/unit/resolveTaskFn.unmocked.spec.js b/test/unit/resolveTaskFn.unmocked.spec.js index f3a4759ae..e60649d09 100644 --- a/test/unit/resolveTaskFn.unmocked.spec.js +++ b/test/unit/resolveTaskFn.unmocked.spec.js @@ -31,7 +31,7 @@ describe('resolveTaskFn', () => { const task2Promise = taskFn2(context) await expect(task2Promise).rejects.toThrowErrorMatchingInlineSnapshot( - `"node -e \\"process.exit(1)\\" [FAILED]"` + `"node -e "process.exit(1)" [FAILED]"` ) await expect(taskPromise).rejects.toThrowErrorMatchingInlineSnapshot(`"node [KILLED]"`) }) diff --git a/test/unit/runAll.spec.js b/test/unit/runAll.spec.js index fc8a6f885..ade3fa875 100644 --- a/test/unit/runAll.spec.js +++ b/test/unit/runAll.spec.js @@ -63,22 +63,22 @@ describe('runAll', () => { it('should resolve the promise with no tasks', async () => { expect.assertions(1) await expect(runAll({ configObject: {}, configPath })).resolves.toMatchInlineSnapshot(` - Object { - "errors": Set {}, - "events": EventEmitter { - "_events": Object {}, - "_eventsCount": 0, - "_maxListeners": undefined, - Symbol(kCapture): false, - }, - "hasPartiallyStagedFiles": null, - "output": Array [ - "→ No staged files found.", - ], - "quiet": false, - "shouldBackup": true, - } - `) + { + "errors": Set {}, + "events": EventEmitter { + "_events": {}, + "_eventsCount": 0, + "_maxListeners": undefined, + Symbol(kCapture): false, + }, + "hasPartiallyStagedFiles": null, + "output": [ + "→ No staged files found.", + ], + "quiet": false, + "shouldBackup": true, + } + `) }) it('should throw when failed to find staged files', async () => { @@ -100,42 +100,42 @@ describe('runAll', () => { it('should print output when no staged files', async () => { expect.assertions(1) await expect(runAll({ configObject: {}, configPath })).resolves.toMatchInlineSnapshot(` - Object { - "errors": Set {}, - "events": EventEmitter { - "_events": Object {}, - "_eventsCount": 0, - "_maxListeners": undefined, - Symbol(kCapture): false, - }, - "hasPartiallyStagedFiles": null, - "output": Array [ - "→ No staged files found.", - ], - "quiet": false, - "shouldBackup": true, - } - `) + { + "errors": Set {}, + "events": EventEmitter { + "_events": {}, + "_eventsCount": 0, + "_maxListeners": undefined, + Symbol(kCapture): false, + }, + "hasPartiallyStagedFiles": null, + "output": [ + "→ No staged files found.", + ], + "quiet": false, + "shouldBackup": true, + } + `) }) it('should not print output when no staged files and quiet', async () => { expect.assertions(1) await expect(runAll({ configObject: {}, configPath, quiet: true })).resolves .toMatchInlineSnapshot(` - Object { - "errors": Set {}, - "events": EventEmitter { - "_events": Object {}, - "_eventsCount": 0, - "_maxListeners": undefined, - Symbol(kCapture): false, - }, - "hasPartiallyStagedFiles": null, - "output": Array [], - "quiet": true, - "shouldBackup": true, - } - `) + { + "errors": Set {}, + "events": EventEmitter { + "_events": {}, + "_eventsCount": 0, + "_maxListeners": undefined, + Symbol(kCapture): false, + }, + "hasPartiallyStagedFiles": null, + "output": [], + "quiet": true, + "shouldBackup": true, + } + `) }) it('should resolve the promise with no files', async () => { @@ -169,8 +169,8 @@ describe('runAll', () => { LOG [STARTED] Running tasks for staged files... LOG [STARTED] Config object — 1 file LOG [STARTED] *.js — 1 file - LOG [STARTED] echo \\"sample\\" - LOG [SUCCESS] echo \\"sample\\" + LOG [STARTED] echo "sample" + LOG [SUCCESS] echo "sample" LOG [SUCCESS] *.js — 1 file LOG [SUCCESS] Config object — 1 file LOG [SUCCESS] Running tasks for staged files... @@ -235,10 +235,10 @@ describe('runAll', () => { LOG [STARTED] Running tasks for staged files... LOG [STARTED] Config object — 1 file LOG [STARTED] *.js — 1 file - LOG [STARTED] echo \\"sample\\" - ERROR [FAILED] echo \\"sample\\" [1] - ERROR [FAILED] echo \\"sample\\" [1] - ERROR [FAILED] echo \\"sample\\" [1] + LOG [STARTED] echo "sample" + ERROR [FAILED] echo "sample" [1] + ERROR [FAILED] echo "sample" [1] + ERROR [FAILED] echo "sample" [1] LOG [STARTED] Applying modifications from tasks... INFO [SKIPPED] Skipped because of errors from tasks. LOG [STARTED] Reverting to original state because of errors... @@ -274,10 +274,10 @@ describe('runAll', () => { LOG [STARTED] Running tasks for staged files... LOG [STARTED] Config object — 1 file LOG [STARTED] *.js — 1 file - LOG [STARTED] echo \\"sample\\" - ERROR [FAILED] echo \\"sample\\" [KILLED] - ERROR [FAILED] echo \\"sample\\" [KILLED] - ERROR [FAILED] echo \\"sample\\" [KILLED] + LOG [STARTED] echo "sample" + ERROR [FAILED] echo "sample" [KILLED] + ERROR [FAILED] echo "sample" [KILLED] + ERROR [FAILED] echo "sample" [KILLED] LOG [STARTED] Applying modifications from tasks... INFO [SKIPPED] Skipped because of errors from tasks. LOG [STARTED] Reverting to original state because of errors...