From 9e70170163a746442bb10b920ae6733aa4ed9841 Mon Sep 17 00:00:00 2001 From: Le Vivilet Date: Mon, 20 Jul 2026 12:18:34 +0000 Subject: [PATCH] feature: add git extension e2e coverage --- packages/e2e/src/git-api-add-all.ts | 35 ++++++++++++++++ .../e2e/src/git-api-add-file-with-spaces.ts | 28 +++++++++++++ packages/e2e/src/git-api-add-nested-file.ts | 30 ++++++++++++++ packages/e2e/src/git-api-add-remote.ts | 31 ++++++++++++++ .../e2e/src/git-api-add-untracked-file.ts | 28 +++++++++++++ packages/e2e/src/git-api-branch-with-slash.ts | 28 +++++++++++++ .../e2e/src/git-api-clean-all-tracked-file.ts | 31 ++++++++++++++ .../git-api-clean-all-untracked-directory.ts | 32 +++++++++++++++ .../src/git-api-commit-special-characters.ts | 36 ++++++++++++++++ packages/e2e/src/git-api-discard-cancel.ts | 26 ++++++++++++ .../e2e/src/git-api-discard-tracked-file.ts | 36 ++++++++++++++++ .../git-api-discard-without-confirmation.ts | 35 ++++++++++++++++ packages/e2e/src/git-api-get-commits.ts | 33 +++++++++++++++ packages/e2e/src/git-api-set-config.ts | 22 ++++++++++ packages/e2e/src/git-api-stage-all.ts | 35 ++++++++++++++++ .../e2e/src/git-api-stash-with-message.ts | 29 +++++++++++++ .../git-api-unstage-all-clean-repository.ts | 26 ++++++++++++ packages/e2e/src/git-api-unstage-all.ts | 41 +++++++++++++++++++ .../git-api-unstage-new-file-with-spaces.ts | 32 +++++++++++++++ .../e2e/src/git-api-unstage-tracked-file.ts | 29 +++++++++++++ 20 files changed, 623 insertions(+) create mode 100644 packages/e2e/src/git-api-add-all.ts create mode 100644 packages/e2e/src/git-api-add-file-with-spaces.ts create mode 100644 packages/e2e/src/git-api-add-nested-file.ts create mode 100644 packages/e2e/src/git-api-add-remote.ts create mode 100644 packages/e2e/src/git-api-add-untracked-file.ts create mode 100644 packages/e2e/src/git-api-branch-with-slash.ts create mode 100644 packages/e2e/src/git-api-clean-all-tracked-file.ts create mode 100644 packages/e2e/src/git-api-clean-all-untracked-directory.ts create mode 100644 packages/e2e/src/git-api-commit-special-characters.ts create mode 100644 packages/e2e/src/git-api-discard-cancel.ts create mode 100644 packages/e2e/src/git-api-discard-tracked-file.ts create mode 100644 packages/e2e/src/git-api-discard-without-confirmation.ts create mode 100644 packages/e2e/src/git-api-get-commits.ts create mode 100644 packages/e2e/src/git-api-set-config.ts create mode 100644 packages/e2e/src/git-api-stage-all.ts create mode 100644 packages/e2e/src/git-api-stash-with-message.ts create mode 100644 packages/e2e/src/git-api-unstage-all-clean-repository.ts create mode 100644 packages/e2e/src/git-api-unstage-all.ts create mode 100644 packages/e2e/src/git-api-unstage-new-file-with-spaces.ts create mode 100644 packages/e2e/src/git-api-unstage-tracked-file.ts diff --git a/packages/e2e/src/git-api-add-all.ts b/packages/e2e/src/git-api-add-all.ts new file mode 100644 index 00000000..235899e7 --- /dev/null +++ b/packages/e2e/src/git-api-add-all.ts @@ -0,0 +1,35 @@ +import type { Test } from '@lvce-editor/test-with-playwright' + +export const name = 'git.add-all' + +export const test: Test = async ({ Command, FileSystem, Git, Workspace }) => { + // arrange + const tmpDir = await FileSystem.getTmpDir({ scheme: 'file' }) + const fileNames = ['first.txt', 'second.txt'] + + await Workspace.setPath(tmpDir) + await FileSystem.setFiles( + fileNames.map((fileName) => ({ + content: `${fileName} content`, + uri: `${tmpDir}/${fileName}`, + })), + ) + await Git.init() + + // act + await Command.execute('ExtensionHost.executeCommand', 'git.addAll') + + // assert + const indexContent = await FileSystem.readFile(`${tmpDir}/.git/index`) + for (const fileName of fileNames) { + if (!indexContent.includes(fileName)) { + throw new Error(`expected ${fileName} in git index`) + } + } + await Git.shouldHaveInvocations([ + { + command: ['git', 'add', '.'], + cwd: tmpDir, + }, + ]) +} diff --git a/packages/e2e/src/git-api-add-file-with-spaces.ts b/packages/e2e/src/git-api-add-file-with-spaces.ts new file mode 100644 index 00000000..bb57bf6b --- /dev/null +++ b/packages/e2e/src/git-api-add-file-with-spaces.ts @@ -0,0 +1,28 @@ +import type { Test } from '@lvce-editor/test-with-playwright' + +export const name = 'git.add-file-with-spaces' + +export const test: Test = async ({ FileSystem, Git, Workspace }) => { + // arrange + const tmpDir = await FileSystem.getTmpDir({ scheme: 'file' }) + const fileName = 'file with spaces.txt' + + await Workspace.setPath(tmpDir) + await FileSystem.writeFile(`${tmpDir}/${fileName}`, 'spaced path') + await Git.init() + + // act + await Git.add(fileName) + + // assert + const indexContent = await FileSystem.readFile(`${tmpDir}/.git/index`) + if (!indexContent.includes(fileName)) { + throw new Error(`expected ${fileName} in git index`) + } + await Git.shouldHaveInvocations([ + { + command: ['git', 'add', fileName], + cwd: tmpDir, + }, + ]) +} diff --git a/packages/e2e/src/git-api-add-nested-file.ts b/packages/e2e/src/git-api-add-nested-file.ts new file mode 100644 index 00000000..29d4121a --- /dev/null +++ b/packages/e2e/src/git-api-add-nested-file.ts @@ -0,0 +1,30 @@ +import type { Test } from '@lvce-editor/test-with-playwright' + +export const name = 'git.add-nested-file' + +export const test: Test = async ({ FileSystem, Git, Workspace }) => { + // arrange + const tmpDir = await FileSystem.getTmpDir({ scheme: 'file' }) + const folderName = 'nested' + const fileName = `${folderName}/file.txt` + + await Workspace.setPath(tmpDir) + await FileSystem.mkdir(`${tmpDir}/${folderName}`) + await FileSystem.writeFile(`${tmpDir}/${fileName}`, 'nested content') + await Git.init() + + // act + await Git.add(fileName) + + // assert + const indexContent = await FileSystem.readFile(`${tmpDir}/.git/index`) + if (!indexContent.includes(fileName)) { + throw new Error(`expected ${fileName} in git index`) + } + await Git.shouldHaveInvocations([ + { + command: ['git', 'add', fileName], + cwd: tmpDir, + }, + ]) +} diff --git a/packages/e2e/src/git-api-add-remote.ts b/packages/e2e/src/git-api-add-remote.ts new file mode 100644 index 00000000..53699b9c --- /dev/null +++ b/packages/e2e/src/git-api-add-remote.ts @@ -0,0 +1,31 @@ +import type { Test } from '@lvce-editor/test-with-playwright' + +export const name = 'git.add-remote' + +export const test: Test = async ({ Command, FileSystem, Git, Workspace }) => { + // arrange + const tmpDir = await FileSystem.getTmpDir({ scheme: 'file' }) + const workspaceDir = `${tmpDir}/workspace` + const remoteName = 'backup' + const remoteUrl = 'https://example.com/repository.git' + + await Workspace.setPath(tmpDir) + const fixtureUrl = import.meta.resolve('../fixtures/git-api-branch') + await Command.execute('ExtensionHost.executeCommand', 'git.loadFixture', fixtureUrl) + await Workspace.setPath(workspaceDir) + + // act + await Git.addRemote(remoteName, remoteUrl) + + // assert + const configContent = await FileSystem.readFile(`${workspaceDir}/.git/config`) + if (!configContent.includes(`[remote "${remoteName}"]`) || !configContent.includes(`url = ${remoteUrl}`)) { + throw new Error(`expected git config to contain ${remoteName} remote, got ${configContent}`) + } + await Git.shouldHaveInvocations([ + { + command: ['git', 'remote', 'add', remoteName, remoteUrl], + cwd: workspaceDir, + }, + ]) +} diff --git a/packages/e2e/src/git-api-add-untracked-file.ts b/packages/e2e/src/git-api-add-untracked-file.ts new file mode 100644 index 00000000..cc4f6c21 --- /dev/null +++ b/packages/e2e/src/git-api-add-untracked-file.ts @@ -0,0 +1,28 @@ +import type { Test } from '@lvce-editor/test-with-playwright' + +export const name = 'git.add-untracked-file' + +export const test: Test = async ({ FileSystem, Git, Workspace }) => { + // arrange + const tmpDir = await FileSystem.getTmpDir({ scheme: 'file' }) + const fileName = 'untracked.txt' + + await Workspace.setPath(tmpDir) + await FileSystem.writeFile(`${tmpDir}/${fileName}`, 'new content') + await Git.init() + + // act + await Git.add(fileName) + + // assert + const indexContent = await FileSystem.readFile(`${tmpDir}/.git/index`) + if (!indexContent.includes(fileName)) { + throw new Error(`expected ${fileName} in git index`) + } + await Git.shouldHaveInvocations([ + { + command: ['git', 'add', fileName], + cwd: tmpDir, + }, + ]) +} diff --git a/packages/e2e/src/git-api-branch-with-slash.ts b/packages/e2e/src/git-api-branch-with-slash.ts new file mode 100644 index 00000000..2cc01f9d --- /dev/null +++ b/packages/e2e/src/git-api-branch-with-slash.ts @@ -0,0 +1,28 @@ +import type { Test } from '@lvce-editor/test-with-playwright' + +export const name = 'git.branch-with-slash' + +export const test: Test = async ({ Command, FileSystem, Git, Workspace }) => { + // arrange + const tmpDir = await FileSystem.getTmpDir({ scheme: 'file' }) + const workspaceDir = `${tmpDir}/workspace` + const branchName = 'feature/nested' + + await Workspace.setPath(tmpDir) + const fixtureUrl = import.meta.resolve('../fixtures/git-api-branch') + await Command.execute('ExtensionHost.executeCommand', 'git.loadFixture', fixtureUrl) + await Workspace.setPath(workspaceDir) + + // act + await Git.branch(branchName) + + // assert + const mainRef = await FileSystem.readFile(`${workspaceDir}/.git/refs/heads/main`) + await FileSystem.shouldHaveFile(`${workspaceDir}/.git/refs/heads/${branchName}`, mainRef) + await Git.shouldHaveInvocations([ + { + command: ['git', 'branch', branchName], + cwd: workspaceDir, + }, + ]) +} diff --git a/packages/e2e/src/git-api-clean-all-tracked-file.ts b/packages/e2e/src/git-api-clean-all-tracked-file.ts new file mode 100644 index 00000000..f9e56ea4 --- /dev/null +++ b/packages/e2e/src/git-api-clean-all-tracked-file.ts @@ -0,0 +1,31 @@ +import type { Test } from '@lvce-editor/test-with-playwright' + +export const name = 'git.clean-all-tracked-file' + +export const test: Test = async ({ Command, FileSystem, Git, Workspace }) => { + // arrange + const tmpDir = await FileSystem.getTmpDir({ scheme: 'file' }) + const workspaceDir = `${tmpDir}/workspace` + + await Workspace.setPath(tmpDir) + const fixtureUrl = import.meta.resolve('../fixtures/git-api-branch') + await Command.execute('ExtensionHost.executeCommand', 'git.loadFixture', fixtureUrl) + await Workspace.setPath(workspaceDir) + await FileSystem.writeFile(`${workspaceDir}/file.txt`, 'modified content') + + // act + await Git.cleanAll() + + // assert + await FileSystem.shouldHaveFile(`${workspaceDir}/file.txt`, 'main branch') + await Git.shouldHaveInvocations([ + { + command: ['git', 'restore', '--', '.'], + cwd: workspaceDir, + }, + { + command: ['git', 'clean', '-fd'], + cwd: workspaceDir, + }, + ]) +} diff --git a/packages/e2e/src/git-api-clean-all-untracked-directory.ts b/packages/e2e/src/git-api-clean-all-untracked-directory.ts new file mode 100644 index 00000000..96cd3574 --- /dev/null +++ b/packages/e2e/src/git-api-clean-all-untracked-directory.ts @@ -0,0 +1,32 @@ +import type { Test } from '@lvce-editor/test-with-playwright' + +export const name = 'git.clean-all-untracked-directory' + +export const test: Test = async ({ Command, FileSystem, Git, Workspace }) => { + // arrange + const tmpDir = await FileSystem.getTmpDir({ scheme: 'file' }) + const workspaceDir = `${tmpDir}/workspace` + const folderName = 'generated' + + await Workspace.setPath(tmpDir) + const fixtureUrl = import.meta.resolve('../fixtures/git-api-branch') + await Command.execute('ExtensionHost.executeCommand', 'git.loadFixture', fixtureUrl) + await Workspace.setPath(workspaceDir) + await FileSystem.mkdir(`${workspaceDir}/${folderName}`) + await FileSystem.writeFile(`${workspaceDir}/${folderName}/output.txt`, 'generated content') + + // act + await Git.cleanAll() + + // assert + const dirents = await FileSystem.readDir(workspaceDir) + if (dirents.some((dirent) => dirent.name === folderName)) { + throw new Error(`expected ${folderName} to be deleted`) + } + await Git.shouldHaveInvocations([ + { + command: ['git', 'clean', '-fd'], + cwd: workspaceDir, + }, + ]) +} diff --git a/packages/e2e/src/git-api-commit-special-characters.ts b/packages/e2e/src/git-api-commit-special-characters.ts new file mode 100644 index 00000000..52ae91fa --- /dev/null +++ b/packages/e2e/src/git-api-commit-special-characters.ts @@ -0,0 +1,36 @@ +import type { Test } from '@lvce-editor/test-with-playwright' + +export const name = 'git.commit-special-characters' + +type GitCommit = { + readonly hash: string + readonly message: string +} + +export const test: Test = async ({ Command, FileSystem, Git, Workspace }) => { + // arrange + const tmpDir = await FileSystem.getTmpDir({ scheme: 'file' }) + const message = "It's ready: [e2e]" + + await Workspace.setPath(tmpDir) + await Git.init() + await Git.setConfig('user.name', 'Test User') + await Git.setConfig('user.email', 'test@example.com') + await FileSystem.writeFile(`${tmpDir}/file.txt`, 'content') + await Git.add('file.txt') + + // act + await Git.commit(message) + + // assert + const commits = (await Command.execute('ExtensionHost.executeCommand', 'git.getCommits')) as readonly GitCommit[] + if (commits.length !== 1 || commits[0].message !== message || !commits[0].hash) { + throw new Error(`expected commit ${JSON.stringify(message)}, got ${JSON.stringify(commits)}`) + } + await Git.shouldHaveInvocations([ + { + command: ['git', 'commit', '-m', message], + cwd: tmpDir, + }, + ]) +} diff --git a/packages/e2e/src/git-api-discard-cancel.ts b/packages/e2e/src/git-api-discard-cancel.ts new file mode 100644 index 00000000..e0e9b63e --- /dev/null +++ b/packages/e2e/src/git-api-discard-cancel.ts @@ -0,0 +1,26 @@ +import type { Test } from '@lvce-editor/test-with-playwright' + +export const name = 'git.discard-cancel' + +export const test: Test = async ({ Command, Dialog, FileSystem, Settings, Workspace }) => { + // arrange + const tmpDir = await FileSystem.getTmpDir({ scheme: 'file' }) + const workspaceDir = `${tmpDir}/workspace` + const fileName = 'file.txt' + + await Workspace.setPath(tmpDir) + const fixtureUrl = import.meta.resolve('../fixtures/git-api-branch') + await Command.execute('ExtensionHost.executeCommand', 'git.loadFixture', fixtureUrl) + await Workspace.setPath(workspaceDir) + await Settings.update({ + 'git.confirmDiscard': true, + }) + await Dialog.mockConfirm(() => false) + await FileSystem.writeFile(`${workspaceDir}/${fileName}`, 'modified content') + + // act + await Command.execute('ExtensionHost.executeCommand', 'git.discard', fileName) + + // assert + await FileSystem.shouldHaveFile(`${workspaceDir}/${fileName}`, 'modified content') +} diff --git a/packages/e2e/src/git-api-discard-tracked-file.ts b/packages/e2e/src/git-api-discard-tracked-file.ts new file mode 100644 index 00000000..5388d028 --- /dev/null +++ b/packages/e2e/src/git-api-discard-tracked-file.ts @@ -0,0 +1,36 @@ +import type { Test } from '@lvce-editor/test-with-playwright' + +export const name = 'git.discard-tracked-file' + +export const test: Test = async ({ Command, Dialog, FileSystem, Git, Settings, Workspace }) => { + // arrange + const tmpDir = await FileSystem.getTmpDir({ scheme: 'file' }) + const workspaceDir = `${tmpDir}/workspace` + const fileName = 'file.txt' + + await Workspace.setPath(tmpDir) + const fixtureUrl = import.meta.resolve('../fixtures/git-api-branch') + await Command.execute('ExtensionHost.executeCommand', 'git.loadFixture', fixtureUrl) + await Workspace.setPath(workspaceDir) + await Settings.update({ + 'git.confirmDiscard': true, + }) + await Dialog.mockConfirm(() => true) + await FileSystem.writeFile(`${workspaceDir}/${fileName}`, 'modified content') + + // act + await Command.execute('ExtensionHost.executeCommand', 'git.discard', fileName) + + // assert + await FileSystem.shouldHaveFile(`${workspaceDir}/${fileName}`, 'main branch') + await Git.shouldHaveInvocations([ + { + command: ['git', 'status', '--porcelain', '-uall'], + cwd: workspaceDir, + }, + { + command: ['git', 'restore', '--', fileName], + cwd: workspaceDir, + }, + ]) +} diff --git a/packages/e2e/src/git-api-discard-without-confirmation.ts b/packages/e2e/src/git-api-discard-without-confirmation.ts new file mode 100644 index 00000000..aecbb684 --- /dev/null +++ b/packages/e2e/src/git-api-discard-without-confirmation.ts @@ -0,0 +1,35 @@ +import type { Test } from '@lvce-editor/test-with-playwright' + +export const name = 'git.discard-without-confirmation' + +export const test: Test = async ({ Command, FileSystem, Git, Settings, Workspace }) => { + // arrange + const tmpDir = await FileSystem.getTmpDir({ scheme: 'file' }) + const workspaceDir = `${tmpDir}/workspace` + const fileName = 'file.txt' + + await Workspace.setPath(tmpDir) + const fixtureUrl = import.meta.resolve('../fixtures/git-api-branch') + await Command.execute('ExtensionHost.executeCommand', 'git.loadFixture', fixtureUrl) + await Workspace.setPath(workspaceDir) + await Settings.update({ + 'git.confirmDiscard': false, + }) + await FileSystem.writeFile(`${workspaceDir}/${fileName}`, 'modified content') + + // act + await Command.execute('ExtensionHost.executeCommand', 'git.discard', fileName) + + // assert + await FileSystem.shouldHaveFile(`${workspaceDir}/${fileName}`, 'main branch') + await Git.shouldHaveInvocations([ + { + command: ['git', 'status', '--porcelain', '-uall'], + cwd: workspaceDir, + }, + { + command: ['git', 'restore', '--', fileName], + cwd: workspaceDir, + }, + ]) +} diff --git a/packages/e2e/src/git-api-get-commits.ts b/packages/e2e/src/git-api-get-commits.ts new file mode 100644 index 00000000..5d851e30 --- /dev/null +++ b/packages/e2e/src/git-api-get-commits.ts @@ -0,0 +1,33 @@ +import type { Test } from '@lvce-editor/test-with-playwright' + +export const name = 'git.get-commits' + +type GitCommit = { + readonly hash: string + readonly message: string +} + +export const test: Test = async ({ Command, FileSystem, Git, Workspace }) => { + // arrange + const tmpDir = await FileSystem.getTmpDir({ scheme: 'file' }) + const workspaceDir = `${tmpDir}/workspace` + + await Workspace.setPath(tmpDir) + const fixtureUrl = import.meta.resolve('../fixtures/git-api-branch') + await Command.execute('ExtensionHost.executeCommand', 'git.loadFixture', fixtureUrl) + await Workspace.setPath(workspaceDir) + + // act + const commits = (await Command.execute('ExtensionHost.executeCommand', 'git.getCommits')) as readonly GitCommit[] + + // assert + if (commits.length !== 1 || commits[0].message !== 'Initial commit' || !commits[0].hash) { + throw new Error(`expected initial commit, got ${JSON.stringify(commits)}`) + } + await Git.shouldHaveInvocations([ + { + command: ['git', 'log', '--format=%H%x09%s'], + cwd: workspaceDir, + }, + ]) +} diff --git a/packages/e2e/src/git-api-set-config.ts b/packages/e2e/src/git-api-set-config.ts new file mode 100644 index 00000000..5325efd0 --- /dev/null +++ b/packages/e2e/src/git-api-set-config.ts @@ -0,0 +1,22 @@ +import type { Test } from '@lvce-editor/test-with-playwright' + +export const name = 'git.set-config' + +export const test: Test = async ({ Command, FileSystem, Git, Workspace }) => { + // arrange + const tmpDir = await FileSystem.getTmpDir({ scheme: 'file' }) + const key = 'user.name' + const value = 'E2E Test User' + + await Workspace.setPath(tmpDir) + await Git.init() + + // act + await Command.execute('ExtensionHost.executeCommand', 'git.setConfig', key, value) + + // assert + const configContent = await FileSystem.readFile(`${tmpDir}/.git/config`) + if (!configContent.includes('name = E2E Test User')) { + throw new Error(`expected git config to contain user name, got ${configContent}`) + } +} diff --git a/packages/e2e/src/git-api-stage-all.ts b/packages/e2e/src/git-api-stage-all.ts new file mode 100644 index 00000000..7c5fa37c --- /dev/null +++ b/packages/e2e/src/git-api-stage-all.ts @@ -0,0 +1,35 @@ +import type { Test } from '@lvce-editor/test-with-playwright' + +export const name = 'git.stage-all' + +export const test: Test = async ({ Command, FileSystem, Git, Workspace }) => { + // arrange + const tmpDir = await FileSystem.getTmpDir({ scheme: 'file' }) + const fileNames = ['alpha.txt', 'beta.txt'] + + await Workspace.setPath(tmpDir) + await FileSystem.setFiles( + fileNames.map((fileName) => ({ + content: `${fileName} content`, + uri: `${tmpDir}/${fileName}`, + })), + ) + await Git.init() + + // act + await Command.execute('ExtensionHost.executeCommand', 'git.stageAll') + + // assert + const indexContent = await FileSystem.readFile(`${tmpDir}/.git/index`) + for (const fileName of fileNames) { + if (!indexContent.includes(fileName)) { + throw new Error(`expected ${fileName} in git index`) + } + } + await Git.shouldHaveInvocations([ + { + command: ['git', 'add', '.'], + cwd: tmpDir, + }, + ]) +} diff --git a/packages/e2e/src/git-api-stash-with-message.ts b/packages/e2e/src/git-api-stash-with-message.ts new file mode 100644 index 00000000..358b1bff --- /dev/null +++ b/packages/e2e/src/git-api-stash-with-message.ts @@ -0,0 +1,29 @@ +import type { Test } from '@lvce-editor/test-with-playwright' + +export const name = 'git.stash-with-message' + +export const test: Test = async ({ Command, FileSystem, Git, Workspace }) => { + // arrange + const tmpDir = await FileSystem.getTmpDir({ scheme: 'file' }) + const workspaceDir = `${tmpDir}/workspace` + const message = 'work in progress' + + await Workspace.setPath(tmpDir) + const fixtureUrl = import.meta.resolve('../fixtures/git-api-stash') + await Command.execute('ExtensionHost.executeCommand', 'git.loadFixture', fixtureUrl) + await Workspace.setPath(workspaceDir) + + // act + await Command.execute('ExtensionHost.executeCommand', 'git.stash', { + message, + }) + + // assert + await FileSystem.shouldHaveFile(`${workspaceDir}/file.txt`, 'initial content') + await Git.shouldHaveInvocations([ + { + command: ['git', 'stash', 'push', '--message', message], + cwd: workspaceDir, + }, + ]) +} diff --git a/packages/e2e/src/git-api-unstage-all-clean-repository.ts b/packages/e2e/src/git-api-unstage-all-clean-repository.ts new file mode 100644 index 00000000..6fdc61bb --- /dev/null +++ b/packages/e2e/src/git-api-unstage-all-clean-repository.ts @@ -0,0 +1,26 @@ +import type { Test } from '@lvce-editor/test-with-playwright' + +export const name = 'git.unstage-all-clean-repository' + +export const test: Test = async ({ Command, FileSystem, Git, Workspace }) => { + // arrange + const tmpDir = await FileSystem.getTmpDir({ scheme: 'file' }) + const workspaceDir = `${tmpDir}/workspace` + + await Workspace.setPath(tmpDir) + const fixtureUrl = import.meta.resolve('../fixtures/git-api-branch') + await Command.execute('ExtensionHost.executeCommand', 'git.loadFixture', fixtureUrl) + await Workspace.setPath(workspaceDir) + + // act + await Command.execute('ExtensionHost.executeCommand', 'git.unstageAll') + + // assert + await FileSystem.shouldHaveFile(`${workspaceDir}/file.txt`, 'main branch') + await Git.shouldHaveInvocations([ + { + command: ['git', 'restore', '--staged', '.'], + cwd: workspaceDir, + }, + ]) +} diff --git a/packages/e2e/src/git-api-unstage-all.ts b/packages/e2e/src/git-api-unstage-all.ts new file mode 100644 index 00000000..69921358 --- /dev/null +++ b/packages/e2e/src/git-api-unstage-all.ts @@ -0,0 +1,41 @@ +import type { Test } from '@lvce-editor/test-with-playwright' + +export const name = 'git.unstage-all' + +export const test: Test = async ({ Command, FileSystem, Git, Workspace }) => { + // arrange + const tmpDir = await FileSystem.getTmpDir({ scheme: 'file' }) + const workspaceDir = `${tmpDir}/workspace` + const newFileName = 'new.txt' + + await Workspace.setPath(tmpDir) + const fixtureUrl = import.meta.resolve('../fixtures/git-api-branch') + await Command.execute('ExtensionHost.executeCommand', 'git.loadFixture', fixtureUrl) + await Workspace.setPath(workspaceDir) + await FileSystem.setFiles([ + { + content: 'modified content', + uri: `${workspaceDir}/file.txt`, + }, + { + content: 'new content', + uri: `${workspaceDir}/${newFileName}`, + }, + ]) + await Command.execute('ExtensionHost.executeCommand', 'git.stageAll') + + // act + await Command.execute('ExtensionHost.executeCommand', 'git.unstageAll') + + // assert + const indexContent = await FileSystem.readFile(`${workspaceDir}/.git/index`) + if (indexContent.includes(newFileName)) { + throw new Error(`expected ${newFileName} to be removed from git index`) + } + await Git.shouldHaveInvocations([ + { + command: ['git', 'restore', '--staged', '.'], + cwd: workspaceDir, + }, + ]) +} diff --git a/packages/e2e/src/git-api-unstage-new-file-with-spaces.ts b/packages/e2e/src/git-api-unstage-new-file-with-spaces.ts new file mode 100644 index 00000000..322ae711 --- /dev/null +++ b/packages/e2e/src/git-api-unstage-new-file-with-spaces.ts @@ -0,0 +1,32 @@ +import type { Test } from '@lvce-editor/test-with-playwright' + +export const name = 'git.unstage-new-file-with-spaces' + +export const test: Test = async ({ Command, FileSystem, Git, Workspace }) => { + // arrange + const tmpDir = await FileSystem.getTmpDir({ scheme: 'file' }) + const workspaceDir = `${tmpDir}/workspace` + const fileName = 'new file.txt' + + await Workspace.setPath(tmpDir) + const fixtureUrl = import.meta.resolve('../fixtures/git-api-branch') + await Command.execute('ExtensionHost.executeCommand', 'git.loadFixture', fixtureUrl) + await Workspace.setPath(workspaceDir) + await FileSystem.writeFile(`${workspaceDir}/${fileName}`, 'new content') + await Git.add(fileName) + + // act + await Git.unstage(fileName) + + // assert + const indexContent = await FileSystem.readFile(`${workspaceDir}/.git/index`) + if (indexContent.includes(fileName)) { + throw new Error(`expected ${fileName} to be removed from git index`) + } + await Git.shouldHaveInvocations([ + { + command: ['git', 'restore', '--staged', '--', fileName], + cwd: workspaceDir, + }, + ]) +} diff --git a/packages/e2e/src/git-api-unstage-tracked-file.ts b/packages/e2e/src/git-api-unstage-tracked-file.ts new file mode 100644 index 00000000..bf08a526 --- /dev/null +++ b/packages/e2e/src/git-api-unstage-tracked-file.ts @@ -0,0 +1,29 @@ +import type { Test } from '@lvce-editor/test-with-playwright' + +export const name = 'git.unstage-tracked-file' + +export const test: Test = async ({ Command, FileSystem, Git, Workspace }) => { + // arrange + const tmpDir = await FileSystem.getTmpDir({ scheme: 'file' }) + const workspaceDir = `${tmpDir}/workspace` + const fileName = 'file.txt' + + await Workspace.setPath(tmpDir) + const fixtureUrl = import.meta.resolve('../fixtures/git-api-branch') + await Command.execute('ExtensionHost.executeCommand', 'git.loadFixture', fixtureUrl) + await Workspace.setPath(workspaceDir) + await FileSystem.writeFile(`${workspaceDir}/${fileName}`, 'modified content') + await Git.add(fileName) + + // act + await Git.unstage(fileName) + + // assert + await FileSystem.shouldHaveFile(`${workspaceDir}/${fileName}`, 'modified content') + await Git.shouldHaveInvocations([ + { + command: ['git', 'restore', '--staged', '--', fileName], + cwd: workspaceDir, + }, + ]) +}