Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions packages/e2e/src/git-api-add-all.ts
Original file line number Diff line number Diff line change
@@ -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,
},
])
}
28 changes: 28 additions & 0 deletions packages/e2e/src/git-api-add-file-with-spaces.ts
Original file line number Diff line number Diff line change
@@ -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,
},
])
}
30 changes: 30 additions & 0 deletions packages/e2e/src/git-api-add-nested-file.ts
Original file line number Diff line number Diff line change
@@ -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,
},
])
}
31 changes: 31 additions & 0 deletions packages/e2e/src/git-api-add-remote.ts
Original file line number Diff line number Diff line change
@@ -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,
},
])
}
28 changes: 28 additions & 0 deletions packages/e2e/src/git-api-add-untracked-file.ts
Original file line number Diff line number Diff line change
@@ -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,
},
])
}
28 changes: 28 additions & 0 deletions packages/e2e/src/git-api-branch-with-slash.ts
Original file line number Diff line number Diff line change
@@ -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,
},
])
}
31 changes: 31 additions & 0 deletions packages/e2e/src/git-api-clean-all-tracked-file.ts
Original file line number Diff line number Diff line change
@@ -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,
},
])
}
32 changes: 32 additions & 0 deletions packages/e2e/src/git-api-clean-all-untracked-directory.ts
Original file line number Diff line number Diff line change
@@ -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,
},
])
}
36 changes: 36 additions & 0 deletions packages/e2e/src/git-api-commit-special-characters.ts
Original file line number Diff line number Diff line change
@@ -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,
},
])
}
26 changes: 26 additions & 0 deletions packages/e2e/src/git-api-discard-cancel.ts
Original file line number Diff line number Diff line change
@@ -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')
}
36 changes: 36 additions & 0 deletions packages/e2e/src/git-api-discard-tracked-file.ts
Original file line number Diff line number Diff line change
@@ -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,
},
])
}
35 changes: 35 additions & 0 deletions packages/e2e/src/git-api-discard-without-confirmation.ts
Original file line number Diff line number Diff line change
@@ -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,
},
])
}
Loading
Loading