Skip to content

Commit d678b9a

Browse files
committed
chore: refactor test utils to typescript
1 parent b01152d commit d678b9a

File tree

14 files changed

+164
-199
lines changed

14 files changed

+164
-199
lines changed

.vscode/launch.json

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
{
2+
// Use IntelliSense to learn about possible attributes.
3+
// Hover to view descriptions of existing attributes.
4+
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
5+
"version": "0.2.0",
6+
"configurations": [
7+
{
8+
"type": "node",
9+
"request": "launch",
10+
"name": "Jest Test Current file",
11+
"program": "${workspaceFolder}/node_modules/jest/bin/jest.js",
12+
"cwd": "${workspaceFolder}",
13+
"args": [
14+
"--runInBand",
15+
"--no-cache",
16+
"--no-coverage",
17+
"${fileBasename}"
18+
],
19+
"sourceMaps": true,
20+
"console": "integratedTerminal",
21+
"internalConsoleOptions": "neverOpen"
22+
}
23+
]
24+
}

@commitlint/cli/package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,7 @@
6767
"pkg-dir": "4.2.0",
6868
"resolve-bin": "0.4.0",
6969
"sander": "0.6.0",
70-
"string-to-stream": "3.0.1",
71-
"tmp": "0.1.0"
70+
"string-to-stream": "3.0.1"
7271
},
7372
"dependencies": {
7473
"@commitlint/format": "^8.3.4",

@packages/test/package.json

Lines changed: 7 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -6,37 +6,6 @@
66
"files": [
77
"lib/"
88
],
9-
"scripts": {
10-
"build": "cross-env NODE_ENV=production babel src --out-dir lib --source-maps",
11-
"start": "concurrently \"ava --watch --verbose\" \"yarn run watch\"",
12-
"test": "ava --verbose",
13-
"watch": "babel src --out-dir lib --watch --source-maps"
14-
},
15-
"ava": {
16-
"files": [
17-
"src/**/*.test.js",
18-
"!lib/**/*"
19-
],
20-
"source": [
21-
"src/**/*.js",
22-
"!lib/**/*"
23-
],
24-
"babel": {
25-
"testOptions": {
26-
"presets": [
27-
"babel-preset-commitlint"
28-
]
29-
}
30-
},
31-
"require": [
32-
"@babel/register"
33-
]
34-
},
35-
"babel": {
36-
"presets": [
37-
"babel-preset-commitlint"
38-
]
39-
},
409
"engines": {
4110
"node": ">=4"
4211
},
@@ -59,16 +28,13 @@
5928
},
6029
"license": "MIT",
6130
"dependencies": {
62-
"@marionebl/sander": "0.6.1",
31+
"@types/execa": "^0.9.0",
32+
"@types/fs-extra": "^8.0.1",
33+
"@types/tmp": "^0.1.0",
6334
"execa": "0.11.0",
64-
"pkg-dir": "4.2.0"
35+
"fs-extra": "^8.1.0",
36+
"pkg-dir": "4.2.0",
37+
"tmp": "0.1.0"
6538
},
66-
"devDependencies": {
67-
"@babel/core": "^7.7.7",
68-
"@babel/cli": "^7.7.7",
69-
"@babel/register": "^7.7.7",
70-
"babel-preset-commitlint": "^8.2.0",
71-
"concurrently": "3.5.1",
72-
"cross-env": "5.1.1"
73-
}
39+
"devDependencies": {}
7440
}

@packages/test/src/fix.js

Lines changed: 0 additions & 25 deletions
This file was deleted.

@packages/test/src/fix.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import tmp from 'tmp';
2+
import fs from 'fs-extra';
3+
import path from 'path';
4+
import pkgDir from 'pkg-dir';
5+
6+
async function bootstrap(fixture?: string): Promise<string> {
7+
const tmpDir = tmp.dirSync({
8+
keep: false,
9+
unsafeCleanup: true
10+
});
11+
12+
if (typeof fixture !== 'undefined') {
13+
const packageDir = await pkgDir();
14+
if (!packageDir) {
15+
throw new Error(`ENOENT, no such file or directory '${packageDir}'`);
16+
}
17+
18+
await fs.copy(path.join(packageDir, fixture), tmpDir.name);
19+
}
20+
21+
return tmpDir.name;
22+
}
23+
24+
export {bootstrap};

@packages/test/src/git.js

Lines changed: 0 additions & 48 deletions
This file was deleted.

@packages/test/src/git.ts

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import execa from 'execa';
2+
3+
import * as fix from './fix';
4+
5+
export async function bootstrap(fixture?: string) {
6+
const cwd = await fix.bootstrap(fixture);
7+
8+
await init(cwd);
9+
return cwd;
10+
}
11+
12+
export async function clone(source: string, ...args: string[]) {
13+
const cwd = await fix.bootstrap();
14+
15+
await execa('git', ['clone', ...args, source, cwd]);
16+
await setup(cwd);
17+
return cwd;
18+
}
19+
20+
export async function init(cwd: string) {
21+
await execa('git', ['init', cwd]);
22+
await setup(cwd);
23+
return cwd;
24+
}
25+
26+
async function setup(cwd: string) {
27+
try {
28+
await execa('git', ['config', 'user.name', 'ava'], {cwd});
29+
await execa('git', ['config', 'user.email', '[email protected]'], {cwd});
30+
await execa('git', ['config', 'commit.gpgsign', 'false'], {cwd});
31+
} catch (err) {
32+
console.warn(`git config in ${cwd} failed`, err.message);
33+
}
34+
}

@packages/test/src/index.test.js

Lines changed: 0 additions & 14 deletions
This file was deleted.

@packages/test/src/index.test.ts

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import * as u from '.';
2+
import os from 'os';
3+
import path from 'path';
4+
import fs from 'fs-extra';
5+
6+
test('exports a git namespace', () => {
7+
expect(typeof u.git).toBe('object');
8+
});
9+
10+
test('git namespace has bootstrap', () => {
11+
expect(typeof u.git.bootstrap).toBe('function');
12+
});
13+
14+
test('git namespace has clone', () => {
15+
expect(typeof u.git.clone).toBe('function');
16+
});
17+
18+
test('expect to create tmp directory', async () => {
19+
const directory = await u.git.bootstrap();
20+
expect(directory).toContain('tmp-');
21+
expect(directory).toContain(os.tmpdir());
22+
});
23+
24+
test('expect to create tmp from directory from src', async () => {
25+
const directory = await u.git.bootstrap('.github');
26+
expect(directory).toContain('tmp-');
27+
expect(directory).toContain(os.tmpdir());
28+
29+
const indexFile = path.join(directory, 'ISSUE_TEMPLATE.md');
30+
expect(fs.existsSync(indexFile)).toBeTruthy();
31+
32+
expect(fs.existsSync(directory)).toBeFalsy();
33+
});
File renamed without changes.

@packages/test/src/npm.js renamed to @packages/test/src/npm.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
11
import execa from 'execa';
2-
import * as sander from '@marionebl/sander';
2+
import path from 'path';
3+
import fs from 'fs-extra';
34

45
import * as git from './git';
56

6-
export {bootstrap};
7-
8-
async function bootstrap(fixture) {
7+
export async function bootstrap(fixture: string) {
98
const cwd = await git.bootstrap(fixture);
109

11-
if (await sander.exists(cwd, 'package.json')) {
10+
if (await fs.pathExists(path.join(cwd, 'package.json'))) {
1211
await execa('npm', ['install'], {cwd});
1312
}
1413

@packages/test/tsconfig.json

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"extends": "../../tsconfig.shared.json",
3+
"compilerOptions": {
4+
"composite": true,
5+
"rootDir": "./src",
6+
"outDir": "./lib"
7+
},
8+
"include": [
9+
"./src"
10+
],
11+
"exclude": [
12+
"./src/**/*.test.ts",
13+
"./lib/**/*"
14+
]
15+
}

tsconfig.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
"include": [],
44
"extends": "./tsconfig.shared.json",
55
"references": [
6+
{ "path": "@packages/test" },
67
{ "path": "@commitlint/ensure" },
78
{ "path": "@commitlint/execute-rule" },
89
{ "path": "@commitlint/format" },

0 commit comments

Comments
 (0)