@thegetty/quire-cli 1.0.0-rc.34 → 1.0.0-rc.36
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +36 -0
- package/README.md +9 -0
- package/bin/cli.js +19 -1
- package/package.json +21 -8
- package/schemas/config.schema.json +194 -0
- package/schemas/figures.schema.json +56 -0
- package/schemas/layout.schema.json +5 -0
- package/schemas/objects.schema.json +62 -0
- package/schemas/publication.schema.json +140 -0
- package/schemas/references.schema.json +29 -0
- package/src/Command.js +26 -6
- package/src/Command.spec.js +99 -0
- package/src/commands/README.md +213 -122
- package/src/commands/build.js +46 -37
- package/src/commands/build.spec.js +113 -0
- package/src/commands/build.test.js +402 -0
- package/src/commands/clean.js +25 -19
- package/src/commands/clean.spec.js +108 -0
- package/src/commands/clean.test.js +260 -0
- package/src/commands/config.js +251 -0
- package/src/commands/config.spec.js +107 -0
- package/src/commands/config.test.js +715 -0
- package/src/commands/create.js +42 -14
- package/src/commands/create.spec.js +112 -0
- package/src/commands/create.test.js +415 -0
- package/src/commands/epub.js +59 -30
- package/src/commands/epub.spec.js +114 -0
- package/src/commands/epub.test.js +503 -0
- package/src/commands/index.js +9 -2
- package/src/commands/info.js +18 -24
- package/src/commands/info.spec.js +64 -0
- package/src/commands/info.test.js +415 -0
- package/src/commands/pdf.js +58 -84
- package/src/commands/pdf.spec.js +114 -0
- package/src/commands/pdf.test.js +464 -0
- package/src/commands/preview.js +26 -31
- package/src/commands/preview.spec.js +97 -0
- package/src/commands/preview.test.js +250 -0
- package/src/commands/use.js +56 -0
- package/src/commands/use.spec.js +61 -0
- package/src/commands/use.test.js +280 -0
- package/src/commands/validate.js +31 -19
- package/src/commands/validate.spec.js +82 -0
- package/src/commands/validate.test.js +234 -0
- package/src/commands/workflows.js +70 -0
- package/src/errors/build/build-failed-error.js +19 -0
- package/src/errors/build/config-field-missing-error.js +20 -0
- package/src/errors/build/config-file-not-found-error.js +20 -0
- package/src/errors/build/index.js +11 -0
- package/src/errors/index.js +48 -0
- package/src/errors/install/dependency-install-error.js +19 -0
- package/src/errors/install/directory-not-empty-error.js +25 -0
- package/src/errors/install/index.js +12 -0
- package/src/errors/install/invalid-path-error.js +31 -0
- package/src/errors/install/invalid-starter-error.js +27 -0
- package/src/errors/install/version-not-found-error.js +35 -0
- package/src/errors/output/epub-generation-error.js +19 -0
- package/src/errors/output/index.js +14 -0
- package/src/errors/output/invalid-epub-library-error.js +20 -0
- package/src/errors/output/invalid-pdf-library-error.js +20 -0
- package/src/errors/output/missing-build-output-error.js +21 -0
- package/src/errors/output/pdf-generation-error.js +24 -0
- package/src/errors/output/tool-not-found-error.js +37 -0
- package/src/errors/project/index.js +10 -0
- package/src/errors/project/not-in-project-error.js +20 -0
- package/src/errors/project/project-create-error.js +21 -0
- package/src/errors/quire-error.js +27 -0
- package/src/errors/validation/validation-error.js +20 -11
- package/src/helpers/clean.js +1 -1
- package/src/helpers/docs-url.js +32 -0
- package/src/helpers/test-cwd.js +5 -6
- package/src/helpers/test-cwd.test.js +192 -0
- package/src/helpers/which.js +10 -4
- package/src/lib/11ty/README.md +135 -19
- package/src/lib/11ty/api.js +176 -93
- package/src/lib/11ty/cli.js +77 -35
- package/src/lib/11ty/index.js +64 -5
- package/src/lib/11ty/index.test.js +655 -0
- package/src/lib/README.md +275 -0
- package/src/lib/commander/index.js +100 -0
- package/src/lib/commander/index.test.js +86 -0
- package/src/lib/commander/options.js +195 -0
- package/src/lib/commander/options.test.js +109 -0
- package/src/lib/conf/README.md +84 -73
- package/src/lib/conf/config.js +5 -3
- package/src/lib/conf/config.test.js +281 -0
- package/src/lib/conf/defaults.js +44 -0
- package/src/lib/conf/format.js +60 -0
- package/src/lib/conf/format.test.js +106 -0
- package/src/lib/conf/helpers.js +91 -0
- package/src/lib/conf/helpers.test.js +136 -0
- package/src/lib/conf/index.js +22 -0
- package/src/lib/conf/schema.js +53 -8
- package/src/lib/epub/README.md +133 -2
- package/src/lib/epub/engines.js +46 -0
- package/src/lib/epub/epub.js +36 -11
- package/src/lib/epub/index.js +111 -21
- package/src/lib/epub/index.test.js +518 -0
- package/src/lib/epub/pandoc.js +33 -4
- package/src/lib/epub/pandoc.test.js +122 -0
- package/src/lib/epub/schema.js +21 -0
- package/src/lib/error/README.md +170 -0
- package/src/lib/error/handler.js +107 -0
- package/src/lib/git/README.md +151 -2
- package/src/lib/git/index.js +217 -13
- package/src/lib/git/index.spec.js +80 -0
- package/src/lib/git/index.test.js +453 -0
- package/src/lib/installer/index.js +309 -0
- package/src/lib/installer/index.spec.js +83 -0
- package/src/lib/installer/index.test.js +545 -0
- package/src/lib/logger/README.md +424 -0
- package/src/lib/logger/debug.js +90 -0
- package/src/lib/logger/debug.spec.js +130 -0
- package/src/lib/logger/index.js +228 -0
- package/src/lib/logger/index.spec.js +131 -0
- package/src/lib/logger/index.test.js +477 -0
- package/src/lib/npm/README.md +127 -0
- package/src/lib/npm/index.js +198 -0
- package/src/lib/npm/index.spec.js +60 -0
- package/src/lib/npm/index.test.js +355 -0
- package/src/lib/pdf/README.md +131 -0
- package/src/lib/pdf/engines.js +46 -0
- package/src/lib/pdf/index.js +124 -21
- package/src/lib/pdf/index.test.js +708 -0
- package/src/lib/pdf/paged.js +100 -52
- package/src/lib/pdf/paged.test.js +366 -0
- package/src/lib/pdf/prince.js +115 -37
- package/src/lib/pdf/prince.test.js +202 -0
- package/src/lib/pdf/schema.js +21 -0
- package/src/lib/pdf/split.js +61 -33
- package/src/lib/pdf/split.test.js +445 -0
- package/src/lib/process/manager.js +110 -0
- package/src/lib/process/manager.test.js +55 -0
- package/src/lib/project/build.js +143 -0
- package/src/lib/project/build.test.js +253 -0
- package/src/lib/project/config.js +48 -0
- package/src/lib/project/config.test.js +134 -0
- package/src/{helpers/is-quire.js → lib/project/detect.js} +5 -3
- package/src/lib/project/detect.test.js +157 -0
- package/src/lib/project/index.js +40 -0
- package/src/lib/project/paths.js +224 -0
- package/src/lib/project/version.js +110 -0
- package/src/lib/project/version.test.js +350 -0
- package/src/lib/reporter/README.md +211 -2
- package/src/lib/reporter/index.js +512 -0
- package/src/lib/reporter/index.test.js +593 -0
- package/src/main.js +134 -47
- package/src/main.spec.js +61 -0
- package/src/main.test.js +347 -0
- package/src/validators/utils.js +2 -1
- package/src/commands/conf.js +0 -43
- package/src/commands/version.js +0 -43
- package/src/lib/11ty/paths.js +0 -103
- package/src/lib/i18n/README.md +0 -3
- package/src/lib/i18n/config.js +0 -53
- package/src/lib/i18n/index.js +0 -43
- package/src/lib/i18n/localeService.js +0 -58
- package/src/lib/quire/README.md +0 -19
- package/src/lib/quire/index.js +0 -350
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import test from 'ava'
|
|
2
|
+
import git, { Git } from './index.js'
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Git Façade Unit Tests
|
|
6
|
+
*
|
|
7
|
+
* Tests the git façade module interface and API contract.
|
|
8
|
+
* These tests verify the module exports and method signatures
|
|
9
|
+
* without actually executing git commands.
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
// Default singleton export tests
|
|
13
|
+
test('git façade exports a singleton object', (t) => {
|
|
14
|
+
t.truthy(git, 'git should be exported')
|
|
15
|
+
t.is(typeof git, 'object', 'git should be an object')
|
|
16
|
+
})
|
|
17
|
+
|
|
18
|
+
test('git façade singleton has no cwd by default', (t) => {
|
|
19
|
+
t.is(git.cwd, undefined, 'singleton cwd should be undefined')
|
|
20
|
+
})
|
|
21
|
+
|
|
22
|
+
test('git façade has add method', (t) => {
|
|
23
|
+
t.is(typeof git.add, 'function', 'add should be a function')
|
|
24
|
+
})
|
|
25
|
+
|
|
26
|
+
test('git façade has clone method', (t) => {
|
|
27
|
+
t.is(typeof git.clone, 'function', 'clone should be a function')
|
|
28
|
+
})
|
|
29
|
+
|
|
30
|
+
test('git façade has commit method', (t) => {
|
|
31
|
+
t.is(typeof git.commit, 'function', 'commit should be a function')
|
|
32
|
+
})
|
|
33
|
+
|
|
34
|
+
test('git façade has init method', (t) => {
|
|
35
|
+
t.is(typeof git.init, 'function', 'init should be a function')
|
|
36
|
+
})
|
|
37
|
+
|
|
38
|
+
test('git façade has isAvailable method', (t) => {
|
|
39
|
+
t.is(typeof git.isAvailable, 'function', 'isAvailable should be a function')
|
|
40
|
+
})
|
|
41
|
+
|
|
42
|
+
test('git façade has rm method', (t) => {
|
|
43
|
+
t.is(typeof git.rm, 'function', 'rm should be a function')
|
|
44
|
+
})
|
|
45
|
+
|
|
46
|
+
test('git façade has version method', (t) => {
|
|
47
|
+
t.is(typeof git.version, 'function', 'version should be a function')
|
|
48
|
+
})
|
|
49
|
+
|
|
50
|
+
test('isAvailable returns a boolean', (t) => {
|
|
51
|
+
const result = git.isAvailable()
|
|
52
|
+
t.is(typeof result, 'boolean', 'isAvailable should return a boolean')
|
|
53
|
+
})
|
|
54
|
+
|
|
55
|
+
// Git class export tests
|
|
56
|
+
test('Git class is exported', (t) => {
|
|
57
|
+
t.truthy(Git, 'Git class should be exported')
|
|
58
|
+
t.is(typeof Git, 'function', 'Git should be a constructor')
|
|
59
|
+
})
|
|
60
|
+
|
|
61
|
+
test('Git class can be instantiated with cwd', (t) => {
|
|
62
|
+
const repo = new Git('/path/to/project')
|
|
63
|
+
t.is(repo.cwd, '/path/to/project', 'cwd should be set from constructor')
|
|
64
|
+
})
|
|
65
|
+
|
|
66
|
+
test('Git class can be instantiated without cwd', (t) => {
|
|
67
|
+
const repo = new Git()
|
|
68
|
+
t.is(repo.cwd, undefined, 'cwd should be undefined when not provided')
|
|
69
|
+
})
|
|
70
|
+
|
|
71
|
+
test('Git instance has all methods', (t) => {
|
|
72
|
+
const repo = new Git('/path/to/project')
|
|
73
|
+
t.is(typeof repo.add, 'function', 'add should be a function')
|
|
74
|
+
t.is(typeof repo.clone, 'function', 'clone should be a function')
|
|
75
|
+
t.is(typeof repo.commit, 'function', 'commit should be a function')
|
|
76
|
+
t.is(typeof repo.init, 'function', 'init should be a function')
|
|
77
|
+
t.is(typeof repo.isAvailable, 'function', 'isAvailable should be a function')
|
|
78
|
+
t.is(typeof repo.rm, 'function', 'rm should be a function')
|
|
79
|
+
t.is(typeof repo.version, 'function', 'version should be a function')
|
|
80
|
+
})
|
|
@@ -0,0 +1,453 @@
|
|
|
1
|
+
import esmock from 'esmock'
|
|
2
|
+
import sinon from 'sinon'
|
|
3
|
+
import test from 'ava'
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Git Façade Integration Tests
|
|
7
|
+
*
|
|
8
|
+
* Tests the git façade module behavior with mocked dependencies.
|
|
9
|
+
* Uses esmock to replace execa calls.
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
test.beforeEach((t) => {
|
|
13
|
+
t.context.sandbox = sinon.createSandbox()
|
|
14
|
+
})
|
|
15
|
+
|
|
16
|
+
test.afterEach.always((t) => {
|
|
17
|
+
t.context.sandbox.restore()
|
|
18
|
+
})
|
|
19
|
+
|
|
20
|
+
// Singleton tests (default export, no cwd)
|
|
21
|
+
test('singleton add() stages files without cwd', async (t) => {
|
|
22
|
+
const { sandbox } = t.context
|
|
23
|
+
|
|
24
|
+
const mockExeca = sandbox.stub().resolves({})
|
|
25
|
+
const mockWhich = sandbox.stub().returns('/usr/bin/git')
|
|
26
|
+
|
|
27
|
+
const git = await esmock('./index.js', {
|
|
28
|
+
execa: { execa: mockExeca },
|
|
29
|
+
'#helpers/which.js': { default: mockWhich },
|
|
30
|
+
})
|
|
31
|
+
|
|
32
|
+
await git.add('file.js')
|
|
33
|
+
|
|
34
|
+
t.true(mockExeca.calledOnce)
|
|
35
|
+
t.true(mockExeca.calledWith('git', ['add', 'file.js'], {}))
|
|
36
|
+
})
|
|
37
|
+
|
|
38
|
+
test('singleton clone() uses empty options', async (t) => {
|
|
39
|
+
const { sandbox } = t.context
|
|
40
|
+
|
|
41
|
+
const mockExeca = sandbox.stub().resolves({})
|
|
42
|
+
const mockWhich = sandbox.stub().returns('/usr/bin/git')
|
|
43
|
+
|
|
44
|
+
const git = await esmock('./index.js', {
|
|
45
|
+
execa: { execa: mockExeca },
|
|
46
|
+
'#helpers/which.js': { default: mockWhich },
|
|
47
|
+
})
|
|
48
|
+
|
|
49
|
+
await git.clone('https://github.com/user/repo')
|
|
50
|
+
|
|
51
|
+
t.true(mockExeca.calledWith('git', ['clone', 'https://github.com/user/repo', '.'], {}))
|
|
52
|
+
})
|
|
53
|
+
|
|
54
|
+
test('singleton init() uses empty options', async (t) => {
|
|
55
|
+
const { sandbox } = t.context
|
|
56
|
+
|
|
57
|
+
const mockExeca = sandbox.stub().resolves({})
|
|
58
|
+
const mockWhich = sandbox.stub().returns('/usr/bin/git')
|
|
59
|
+
|
|
60
|
+
const git = await esmock('./index.js', {
|
|
61
|
+
execa: { execa: mockExeca },
|
|
62
|
+
'#helpers/which.js': { default: mockWhich },
|
|
63
|
+
})
|
|
64
|
+
|
|
65
|
+
await git.init()
|
|
66
|
+
|
|
67
|
+
t.true(mockExeca.calledWith('git', ['init'], {}))
|
|
68
|
+
})
|
|
69
|
+
|
|
70
|
+
// Git class instance tests (with cwd)
|
|
71
|
+
test('instance add() stages single file with cwd', async (t) => {
|
|
72
|
+
const { sandbox } = t.context
|
|
73
|
+
|
|
74
|
+
const mockExeca = sandbox.stub().resolves({})
|
|
75
|
+
const mockWhich = sandbox.stub().returns('/usr/bin/git')
|
|
76
|
+
|
|
77
|
+
const { Git } = await esmock('./index.js', {
|
|
78
|
+
execa: { execa: mockExeca },
|
|
79
|
+
'#helpers/which.js': { default: mockWhich },
|
|
80
|
+
})
|
|
81
|
+
|
|
82
|
+
const repo = new Git('/path/to/project')
|
|
83
|
+
await repo.add('file.js')
|
|
84
|
+
|
|
85
|
+
t.true(mockExeca.calledOnce)
|
|
86
|
+
t.true(mockExeca.calledWith('git', ['add', 'file.js'], { cwd: '/path/to/project' }))
|
|
87
|
+
})
|
|
88
|
+
|
|
89
|
+
test('instance add() stages multiple files', async (t) => {
|
|
90
|
+
const { sandbox } = t.context
|
|
91
|
+
|
|
92
|
+
const mockExeca = sandbox.stub().resolves({})
|
|
93
|
+
const mockWhich = sandbox.stub().returns('/usr/bin/git')
|
|
94
|
+
|
|
95
|
+
const { Git } = await esmock('./index.js', {
|
|
96
|
+
execa: { execa: mockExeca },
|
|
97
|
+
'#helpers/which.js': { default: mockWhich },
|
|
98
|
+
})
|
|
99
|
+
|
|
100
|
+
const repo = new Git('/path/to/project')
|
|
101
|
+
await repo.add(['file1.js', 'file2.js'])
|
|
102
|
+
|
|
103
|
+
t.true(mockExeca.calledWith('git', ['add', 'file1.js', 'file2.js'], { cwd: '/path/to/project' }))
|
|
104
|
+
})
|
|
105
|
+
|
|
106
|
+
test('instance add() stages all files with dot notation', async (t) => {
|
|
107
|
+
const { sandbox } = t.context
|
|
108
|
+
|
|
109
|
+
const mockExeca = sandbox.stub().resolves({})
|
|
110
|
+
const mockWhich = sandbox.stub().returns('/usr/bin/git')
|
|
111
|
+
|
|
112
|
+
const { Git } = await esmock('./index.js', {
|
|
113
|
+
execa: { execa: mockExeca },
|
|
114
|
+
'#helpers/which.js': { default: mockWhich },
|
|
115
|
+
})
|
|
116
|
+
|
|
117
|
+
const repo = new Git('/path/to/project')
|
|
118
|
+
await repo.add('.')
|
|
119
|
+
|
|
120
|
+
t.true(mockExeca.calledWith('git', ['add', '.'], { cwd: '/path/to/project' }))
|
|
121
|
+
})
|
|
122
|
+
|
|
123
|
+
test('instance clone() clones repository to destination', async (t) => {
|
|
124
|
+
const { sandbox } = t.context
|
|
125
|
+
|
|
126
|
+
const mockExeca = sandbox.stub().resolves({})
|
|
127
|
+
const mockWhich = sandbox.stub().returns('/usr/bin/git')
|
|
128
|
+
|
|
129
|
+
const { Git } = await esmock('./index.js', {
|
|
130
|
+
execa: { execa: mockExeca },
|
|
131
|
+
'#helpers/which.js': { default: mockWhich },
|
|
132
|
+
})
|
|
133
|
+
|
|
134
|
+
const repo = new Git('/path/to/parent')
|
|
135
|
+
await repo.clone('https://github.com/user/repo', 'dest')
|
|
136
|
+
|
|
137
|
+
t.true(mockExeca.calledOnce)
|
|
138
|
+
t.true(mockExeca.calledWith('git', ['clone', 'https://github.com/user/repo', 'dest'], { cwd: '/path/to/parent' }))
|
|
139
|
+
})
|
|
140
|
+
|
|
141
|
+
test('instance clone() uses current directory as default destination', async (t) => {
|
|
142
|
+
const { sandbox } = t.context
|
|
143
|
+
|
|
144
|
+
const mockExeca = sandbox.stub().resolves({})
|
|
145
|
+
const mockWhich = sandbox.stub().returns('/usr/bin/git')
|
|
146
|
+
|
|
147
|
+
const { Git } = await esmock('./index.js', {
|
|
148
|
+
execa: { execa: mockExeca },
|
|
149
|
+
'#helpers/which.js': { default: mockWhich },
|
|
150
|
+
})
|
|
151
|
+
|
|
152
|
+
const repo = new Git('/path/to/parent')
|
|
153
|
+
await repo.clone('https://github.com/user/repo')
|
|
154
|
+
|
|
155
|
+
t.true(mockExeca.calledWith('git', ['clone', 'https://github.com/user/repo', '.'], { cwd: '/path/to/parent' }))
|
|
156
|
+
})
|
|
157
|
+
|
|
158
|
+
test('instance commit() creates commit with message', async (t) => {
|
|
159
|
+
const { sandbox } = t.context
|
|
160
|
+
|
|
161
|
+
const mockExeca = sandbox.stub().resolves({})
|
|
162
|
+
const mockWhich = sandbox.stub().returns('/usr/bin/git')
|
|
163
|
+
|
|
164
|
+
const { Git } = await esmock('./index.js', {
|
|
165
|
+
execa: { execa: mockExeca },
|
|
166
|
+
'#helpers/which.js': { default: mockWhich },
|
|
167
|
+
})
|
|
168
|
+
|
|
169
|
+
const repo = new Git('/path/to/project')
|
|
170
|
+
await repo.commit('Initial commit')
|
|
171
|
+
|
|
172
|
+
t.true(mockExeca.calledOnce)
|
|
173
|
+
t.true(mockExeca.calledWith('git', ['commit', '-m', 'Initial commit'], { cwd: '/path/to/project' }))
|
|
174
|
+
})
|
|
175
|
+
|
|
176
|
+
test('instance init() initializes repository', async (t) => {
|
|
177
|
+
const { sandbox } = t.context
|
|
178
|
+
|
|
179
|
+
const mockExeca = sandbox.stub().resolves({})
|
|
180
|
+
const mockWhich = sandbox.stub().returns('/usr/bin/git')
|
|
181
|
+
|
|
182
|
+
const { Git } = await esmock('./index.js', {
|
|
183
|
+
execa: { execa: mockExeca },
|
|
184
|
+
'#helpers/which.js': { default: mockWhich },
|
|
185
|
+
})
|
|
186
|
+
|
|
187
|
+
const repo = new Git('/path/to/project')
|
|
188
|
+
await repo.init()
|
|
189
|
+
|
|
190
|
+
t.true(mockExeca.calledOnce)
|
|
191
|
+
t.true(mockExeca.calledWith('git', ['init'], { cwd: '/path/to/project' }))
|
|
192
|
+
})
|
|
193
|
+
|
|
194
|
+
test('instance rm() removes single file', async (t) => {
|
|
195
|
+
const { sandbox } = t.context
|
|
196
|
+
|
|
197
|
+
const mockExeca = sandbox.stub().resolves({})
|
|
198
|
+
const mockWhich = sandbox.stub().returns('/usr/bin/git')
|
|
199
|
+
|
|
200
|
+
const { Git } = await esmock('./index.js', {
|
|
201
|
+
execa: { execa: mockExeca },
|
|
202
|
+
'#helpers/which.js': { default: mockWhich },
|
|
203
|
+
})
|
|
204
|
+
|
|
205
|
+
const repo = new Git('/path/to/project')
|
|
206
|
+
await repo.rm('package.json')
|
|
207
|
+
|
|
208
|
+
t.true(mockExeca.calledOnce)
|
|
209
|
+
t.true(mockExeca.calledWith('git', ['rm', 'package.json'], { cwd: '/path/to/project' }))
|
|
210
|
+
})
|
|
211
|
+
|
|
212
|
+
test('instance rm() removes multiple files', async (t) => {
|
|
213
|
+
const { sandbox } = t.context
|
|
214
|
+
|
|
215
|
+
const mockExeca = sandbox.stub().resolves({})
|
|
216
|
+
const mockWhich = sandbox.stub().returns('/usr/bin/git')
|
|
217
|
+
|
|
218
|
+
const { Git } = await esmock('./index.js', {
|
|
219
|
+
execa: { execa: mockExeca },
|
|
220
|
+
'#helpers/which.js': { default: mockWhich },
|
|
221
|
+
})
|
|
222
|
+
|
|
223
|
+
const repo = new Git('/path/to/project')
|
|
224
|
+
await repo.rm(['file1.js', 'file2.js'])
|
|
225
|
+
|
|
226
|
+
t.true(mockExeca.calledWith('git', ['rm', 'file1.js', 'file2.js'], { cwd: '/path/to/project' }))
|
|
227
|
+
})
|
|
228
|
+
|
|
229
|
+
// Global methods (work same on singleton or instance)
|
|
230
|
+
test('version() returns git version string', async (t) => {
|
|
231
|
+
const { sandbox } = t.context
|
|
232
|
+
|
|
233
|
+
const mockExeca = sandbox.stub().resolves({ stdout: 'git version 2.39.0' })
|
|
234
|
+
const mockWhich = sandbox.stub().returns('/usr/bin/git')
|
|
235
|
+
|
|
236
|
+
const git = await esmock('./index.js', {
|
|
237
|
+
execa: { execa: mockExeca },
|
|
238
|
+
'#helpers/which.js': { default: mockWhich },
|
|
239
|
+
})
|
|
240
|
+
|
|
241
|
+
const result = await git.version()
|
|
242
|
+
|
|
243
|
+
t.is(result, '2.39.0')
|
|
244
|
+
t.true(mockExeca.calledWith('git', ['--version']))
|
|
245
|
+
})
|
|
246
|
+
|
|
247
|
+
test('isAvailable() returns true when git is found in PATH', async (t) => {
|
|
248
|
+
const { sandbox } = t.context
|
|
249
|
+
|
|
250
|
+
const mockWhich = sandbox.stub().returns('/usr/bin/git')
|
|
251
|
+
|
|
252
|
+
const git = await esmock('./index.js', {
|
|
253
|
+
execa: { execa: sandbox.stub() },
|
|
254
|
+
'#helpers/which.js': { default: mockWhich },
|
|
255
|
+
})
|
|
256
|
+
|
|
257
|
+
const result = git.isAvailable()
|
|
258
|
+
|
|
259
|
+
t.true(result)
|
|
260
|
+
t.true(mockWhich.calledWith('git'))
|
|
261
|
+
})
|
|
262
|
+
|
|
263
|
+
test('isAvailable() returns false when git is not found in PATH', async (t) => {
|
|
264
|
+
const { sandbox } = t.context
|
|
265
|
+
|
|
266
|
+
const mockWhich = sandbox.stub().returns(null)
|
|
267
|
+
|
|
268
|
+
const git = await esmock('./index.js', {
|
|
269
|
+
execa: { execa: sandbox.stub() },
|
|
270
|
+
'#helpers/which.js': { default: mockWhich },
|
|
271
|
+
})
|
|
272
|
+
|
|
273
|
+
const result = git.isAvailable()
|
|
274
|
+
|
|
275
|
+
t.false(result)
|
|
276
|
+
})
|
|
277
|
+
|
|
278
|
+
test('instance add() logs stderr via debug when present', async (t) => {
|
|
279
|
+
const { sandbox } = t.context
|
|
280
|
+
|
|
281
|
+
const mockExeca = sandbox.stub().resolves({ stderr: 'warning: LF will be replaced by CRLF' })
|
|
282
|
+
const mockWhich = sandbox.stub().returns('/usr/bin/git')
|
|
283
|
+
const mockDebug = sandbox.stub()
|
|
284
|
+
const mockCreateDebug = sandbox.stub().returns(mockDebug)
|
|
285
|
+
|
|
286
|
+
const { Git } = await esmock('./index.js', {
|
|
287
|
+
execa: { execa: mockExeca },
|
|
288
|
+
'#helpers/which.js': { default: mockWhich },
|
|
289
|
+
'#debug': { default: mockCreateDebug }
|
|
290
|
+
})
|
|
291
|
+
|
|
292
|
+
const repo = new Git('/path/to/project')
|
|
293
|
+
await repo.add('file.js')
|
|
294
|
+
|
|
295
|
+
t.true(mockDebug.calledWith('git add stderr: %s', 'warning: LF will be replaced by CRLF'))
|
|
296
|
+
})
|
|
297
|
+
|
|
298
|
+
test('instance commit() logs stderr via debug when present', async (t) => {
|
|
299
|
+
const { sandbox } = t.context
|
|
300
|
+
|
|
301
|
+
const mockExeca = sandbox.stub().resolves({ stderr: '[main abc1234] commit message' })
|
|
302
|
+
const mockWhich = sandbox.stub().returns('/usr/bin/git')
|
|
303
|
+
const mockDebug = sandbox.stub()
|
|
304
|
+
const mockCreateDebug = sandbox.stub().returns(mockDebug)
|
|
305
|
+
|
|
306
|
+
const { Git } = await esmock('./index.js', {
|
|
307
|
+
execa: { execa: mockExeca },
|
|
308
|
+
'#helpers/which.js': { default: mockWhich },
|
|
309
|
+
'#debug': { default: mockCreateDebug }
|
|
310
|
+
})
|
|
311
|
+
|
|
312
|
+
const repo = new Git('/path/to/project')
|
|
313
|
+
await repo.commit('test commit')
|
|
314
|
+
|
|
315
|
+
t.true(mockDebug.calledWith('git commit stderr: %s', '[main abc1234] commit message'))
|
|
316
|
+
})
|
|
317
|
+
|
|
318
|
+
// isRemoteUrl() tests
|
|
319
|
+
test('isRemoteUrl() returns true for https URLs', async (t) => {
|
|
320
|
+
const { isRemoteUrl } = await import('./index.js')
|
|
321
|
+
|
|
322
|
+
t.true(isRemoteUrl('https://github.com/user/repo'))
|
|
323
|
+
t.true(isRemoteUrl('https://github.com/user/repo.git'))
|
|
324
|
+
})
|
|
325
|
+
|
|
326
|
+
test('isRemoteUrl() returns true for http URLs', async (t) => {
|
|
327
|
+
const { isRemoteUrl } = await import('./index.js')
|
|
328
|
+
|
|
329
|
+
t.true(isRemoteUrl('http://github.com/user/repo'))
|
|
330
|
+
})
|
|
331
|
+
|
|
332
|
+
test('isRemoteUrl() returns true for git@ SSH URLs', async (t) => {
|
|
333
|
+
const { isRemoteUrl } = await import('./index.js')
|
|
334
|
+
|
|
335
|
+
t.true(isRemoteUrl('git@github.com:user/repo.git'))
|
|
336
|
+
t.true(isRemoteUrl('git@gitlab.com:user/repo'))
|
|
337
|
+
})
|
|
338
|
+
|
|
339
|
+
test('isRemoteUrl() returns true for ssh:// URLs', async (t) => {
|
|
340
|
+
const { isRemoteUrl } = await import('./index.js')
|
|
341
|
+
|
|
342
|
+
t.true(isRemoteUrl('ssh://git@github.com/user/repo.git'))
|
|
343
|
+
})
|
|
344
|
+
|
|
345
|
+
test('isRemoteUrl() returns true for git:// URLs', async (t) => {
|
|
346
|
+
const { isRemoteUrl } = await import('./index.js')
|
|
347
|
+
|
|
348
|
+
t.true(isRemoteUrl('git://github.com/user/repo.git'))
|
|
349
|
+
})
|
|
350
|
+
|
|
351
|
+
test('isRemoteUrl() returns false for local paths', async (t) => {
|
|
352
|
+
const { isRemoteUrl } = await import('./index.js')
|
|
353
|
+
|
|
354
|
+
t.false(isRemoteUrl('/path/to/local/repo'))
|
|
355
|
+
t.false(isRemoteUrl('./relative/path'))
|
|
356
|
+
t.false(isRemoteUrl('../parent/path'))
|
|
357
|
+
t.false(isRemoteUrl('local-folder'))
|
|
358
|
+
})
|
|
359
|
+
|
|
360
|
+
// isGitRepository() tests
|
|
361
|
+
test('isGitRepository() returns true when .git directory exists', async (t) => {
|
|
362
|
+
const { sandbox } = t.context
|
|
363
|
+
|
|
364
|
+
const mockFs = {
|
|
365
|
+
existsSync: sandbox.stub().returns(true)
|
|
366
|
+
}
|
|
367
|
+
|
|
368
|
+
const { isGitRepository } = await esmock('./index.js', {
|
|
369
|
+
'node:fs': mockFs
|
|
370
|
+
})
|
|
371
|
+
|
|
372
|
+
const result = isGitRepository('/path/to/repo')
|
|
373
|
+
|
|
374
|
+
t.true(result)
|
|
375
|
+
t.true(mockFs.existsSync.calledOnce)
|
|
376
|
+
})
|
|
377
|
+
|
|
378
|
+
test('isGitRepository() returns false when .git directory does not exist', async (t) => {
|
|
379
|
+
const { sandbox } = t.context
|
|
380
|
+
|
|
381
|
+
const mockFs = {
|
|
382
|
+
existsSync: sandbox.stub().returns(false)
|
|
383
|
+
}
|
|
384
|
+
|
|
385
|
+
const { isGitRepository } = await esmock('./index.js', {
|
|
386
|
+
'node:fs': mockFs
|
|
387
|
+
})
|
|
388
|
+
|
|
389
|
+
const result = isGitRepository('/path/without/git')
|
|
390
|
+
|
|
391
|
+
t.false(result)
|
|
392
|
+
})
|
|
393
|
+
|
|
394
|
+
// validateCloneSource() tests
|
|
395
|
+
test('validateCloneSource() returns valid for remote URLs', async (t) => {
|
|
396
|
+
const { validateCloneSource } = await import('./index.js')
|
|
397
|
+
|
|
398
|
+
t.deepEqual(validateCloneSource('https://github.com/user/repo'), { valid: true })
|
|
399
|
+
t.deepEqual(validateCloneSource('git@github.com:user/repo.git'), { valid: true })
|
|
400
|
+
})
|
|
401
|
+
|
|
402
|
+
test('validateCloneSource() returns invalid when local path does not exist', async (t) => {
|
|
403
|
+
const { sandbox } = t.context
|
|
404
|
+
|
|
405
|
+
const mockFs = {
|
|
406
|
+
existsSync: sandbox.stub().returns(false)
|
|
407
|
+
}
|
|
408
|
+
|
|
409
|
+
const { validateCloneSource } = await esmock('./index.js', {
|
|
410
|
+
'node:fs': mockFs
|
|
411
|
+
})
|
|
412
|
+
|
|
413
|
+
const result = validateCloneSource('/nonexistent/path')
|
|
414
|
+
|
|
415
|
+
t.false(result.valid)
|
|
416
|
+
t.is(result.reason, 'path does not exist')
|
|
417
|
+
})
|
|
418
|
+
|
|
419
|
+
test('validateCloneSource() returns invalid when path is not a git repository', async (t) => {
|
|
420
|
+
const { sandbox } = t.context
|
|
421
|
+
|
|
422
|
+
const mockFs = {
|
|
423
|
+
existsSync: sandbox.stub()
|
|
424
|
+
.onFirstCall().returns(true) // path exists
|
|
425
|
+
.onSecondCall().returns(false) // .git does not exist
|
|
426
|
+
}
|
|
427
|
+
|
|
428
|
+
const { validateCloneSource } = await esmock('./index.js', {
|
|
429
|
+
'node:fs': mockFs
|
|
430
|
+
})
|
|
431
|
+
|
|
432
|
+
const result = validateCloneSource('/path/without/git')
|
|
433
|
+
|
|
434
|
+
t.false(result.valid)
|
|
435
|
+
t.is(result.reason, 'not a git repository')
|
|
436
|
+
})
|
|
437
|
+
|
|
438
|
+
test('validateCloneSource() returns valid for local git repository', async (t) => {
|
|
439
|
+
const { sandbox } = t.context
|
|
440
|
+
|
|
441
|
+
const mockFs = {
|
|
442
|
+
existsSync: sandbox.stub().returns(true) // both path and .git exist
|
|
443
|
+
}
|
|
444
|
+
|
|
445
|
+
const { validateCloneSource } = await esmock('./index.js', {
|
|
446
|
+
'node:fs': mockFs
|
|
447
|
+
})
|
|
448
|
+
|
|
449
|
+
const result = validateCloneSource('/path/to/repo')
|
|
450
|
+
|
|
451
|
+
t.true(result.valid)
|
|
452
|
+
t.is(result.reason, undefined)
|
|
453
|
+
})
|