Skip to content

Commit c2e22ca

Browse files
committed
chore(tests): Add initial tests
1 parent 41ba114 commit c2e22ca

9 files changed

Lines changed: 3637 additions & 61 deletions

File tree

.npmignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
.idea
22
*.iml
3-
yarn-error.log
3+
tests
4+
yarn-error.log

package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,9 @@
55
"types": "lib/index.d.ts",
66
"license": "MIT",
77
"scripts": {
8+
"test": "jest",
89
"build": "tsc",
9-
"prepare": "rm -rf ./lib/* && yarn build"
10+
"prepare": "rm -rf ./lib/* && yarn build && yarn test"
1011
},
1112
"dependencies": {
1213
"chalk": "3.0.0",
@@ -15,6 +16,7 @@
1516
"devDependencies": {
1617
"@types/node": "^13.9.1",
1718
"@types/ramda": "^0.27.0",
19+
"jest": "^26.2.2",
1820
"ts-node": "8.6.2",
1921
"typescript": "3.8.3"
2022
}

src/index.ts

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ type Configs = {
1010
type?: SemVer
1111
skipSemVerFor: Platforms[]
1212
skipCodeFor: Platforms[]
13-
ignoreGitCheck?: boolean
1413
root: string
1514
pbxprojPath: string
1615
buildGradlePath: string
@@ -192,10 +191,10 @@ class PackageJSONManager {
192191
}
193192

194193
export class ProjectFilesManager {
195-
private readonly configs: Configs
196-
private readonly pbx: PBXManager
197-
private readonly buildGradle: BuildGradleManager
198-
private readonly packageJSON: PackageJSONManager
194+
readonly configs: Configs
195+
readonly pbx: PBXManager
196+
readonly buildGradle: BuildGradleManager
197+
readonly packageJSON: PackageJSONManager
199198

200199
constructor(configs: Configs) {
201200
const {
@@ -260,7 +259,19 @@ export class ProjectFilesManager {
260259

261260
}
262261

263-
exec() {
262+
run() {
263+
this.dryRun()
264+
this.pbx.write()
265+
this.buildGradle.write()
266+
this.packageJSON.write()
267+
}
268+
269+
/**
270+
* Separated for testing
271+
*
272+
* This executes changes but don't actually write anything to fs
273+
*/
274+
dryRun() {
264275
const { type, skipSemVerFor, skipCodeFor } = this.configs
265276
const current = this.packageJSON.getVersion()
266277
const next = incrementSemVer(current, type ?? 'minor')
@@ -277,12 +288,10 @@ export class ProjectFilesManager {
277288
this.syncSemver(next)
278289
}
279290

280-
this.pbx.write()
281-
this.buildGradle.write()
282-
this.packageJSON.write()
291+
return this;
283292
}
284293
}
285294

286295
export const versioner = (configs: Configs) => {
287-
new ProjectFilesManager(configs).exec()
296+
new ProjectFilesManager(configs).run()
288297
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
// Jest Snapshot v1, https://goo.gl/fbAQLP
2+
3+
exports[`preserve quotes style 1`] = `
4+
"android {
5+
defaultConfig {
6+
versionCode 2
7+
versionName '1.2.0'
8+
}
9+
}
10+
"
11+
`;
12+
13+
exports[`skip semVer when asked 1`] = `
14+
"android {
15+
defaultConfig {
16+
versionCode 2
17+
versionName \\"1.0.0\\"
18+
}
19+
}
20+
"
21+
`;
22+
23+
exports[`successfully bump version 1`] = `
24+
"android {
25+
defaultConfig {
26+
versionCode 2
27+
versionName \\"1.1.0\\"
28+
}
29+
}
30+
"
31+
`;

tests/android.test.js

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
const path = require('path')
2+
const { ProjectFilesManager } = require('../lib/index')
3+
4+
const makeDefaultManager = ({
5+
type = 'minor',
6+
skipSemVerFor = 'ios',
7+
skipCodeFor = 'ios',
8+
gradleFileName = 'double.gradle'
9+
} = {}) => new ProjectFilesManager({
10+
type,
11+
skipSemVerFor,
12+
skipCodeFor,
13+
root: path.join(__dirname, 'android'),
14+
buildGradlePath: path.join(__dirname, 'android', gradleFileName)
15+
})
16+
17+
test('successfully bump version', () => {
18+
const manager = makeDefaultManager().dryRun()
19+
20+
expect(manager.buildGradle.content).toMatchSnapshot()
21+
})
22+
23+
24+
test('skip semVer when asked', () => {
25+
const manager = makeDefaultManager({ skipSemVerFor: 'all' }).dryRun()
26+
27+
expect(manager.buildGradle.content).toMatchSnapshot()
28+
})
29+
30+
test('preserve quotes style', () => {
31+
const manager = makeDefaultManager({ gradleFileName: 'single.gradle' }).dryRun()
32+
33+
expect(manager.buildGradle.content).toMatchSnapshot()
34+
})

tests/android/double.gradle

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
android {
2+
defaultConfig {
3+
versionCode 1
4+
versionName "1.0.0"
5+
}
6+
}

tests/android/package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"version": "1.0.0"
3+
}

tests/android/single.gradle

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
android {
2+
defaultConfig {
3+
versionCode 1
4+
versionName '1.0.0'
5+
}
6+
}

0 commit comments

Comments
 (0)