Skip to content

test: refactor test utils to typescript #906

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jan 26, 2020
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
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ package-lock.json
lib/
package.json.lerna_backup
/*.iml
tsconfig.tsbuildinfo
tsconfig.tsbuildinfo
24 changes: 24 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "launch",
"name": "Jest Test Current file",
"program": "${workspaceFolder}/node_modules/jest/bin/jest.js",
"cwd": "${workspaceFolder}",
"args": [
"--runInBand",
"--no-cache",
"--no-coverage",
"${fileBasename}"
],
"sourceMaps": true,
"console": "integratedTerminal",
"internalConsoleOptions": "neverOpen"
}
]
}
3 changes: 1 addition & 2 deletions @commitlint/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,7 @@
"pkg-dir": "4.2.0",
"resolve-bin": "0.4.0",
"sander": "0.6.0",
"string-to-stream": "3.0.1",
"tmp": "0.1.0"
"string-to-stream": "3.0.1"
},
"dependencies": {
"@commitlint/format": "^8.3.4",
Expand Down
47 changes: 6 additions & 41 deletions @packages/test/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,37 +6,6 @@
"files": [
"lib/"
],
"scripts": {
"build": "cross-env NODE_ENV=production babel src --out-dir lib --source-maps",
"start": "concurrently \"ava --watch --verbose\" \"yarn run watch\"",
"test": "ava --verbose",
"watch": "babel src --out-dir lib --watch --source-maps"
},
"ava": {
"files": [
"src/**/*.test.js",
"!lib/**/*"
],
"source": [
"src/**/*.js",
"!lib/**/*"
],
"babel": {
"testOptions": {
"presets": [
"babel-preset-commitlint"
]
}
},
"require": [
"@babel/register"
]
},
"babel": {
"presets": [
"babel-preset-commitlint"
]
},
"engines": {
"node": ">=4"
},
Expand All @@ -59,16 +28,12 @@
},
"license": "MIT",
"dependencies": {
"@marionebl/sander": "0.6.1",
"@types/execa": "^0.9.0",
"@types/fs-extra": "^8.0.1",
"@types/tmp": "^0.1.0",
"execa": "0.11.0",
"pkg-dir": "4.2.0"
},
"devDependencies": {
"@babel/core": "^7.7.7",
"@babel/cli": "^7.7.7",
"@babel/register": "^7.7.7",
"babel-preset-commitlint": "^8.2.0",
"concurrently": "3.5.1",
"cross-env": "5.1.1"
"fs-extra": "^8.1.0",
"pkg-dir": "4.2.0",
"tmp": "0.1.0"
}
}
25 changes: 0 additions & 25 deletions @packages/test/src/fix.js

This file was deleted.

24 changes: 24 additions & 0 deletions @packages/test/src/fix.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import tmp from 'tmp';
import fs from 'fs-extra';
import path from 'path';
import pkgDir from 'pkg-dir';

async function bootstrap(fixture?: string): Promise<string> {
const tmpDir = tmp.dirSync({
keep: false,
unsafeCleanup: true
});

if (typeof fixture !== 'undefined') {
const packageDir = await pkgDir();
if (!packageDir) {
throw new Error(`ENOENT, no such file or directory '${packageDir}'`);
}

await fs.copy(path.join(packageDir, fixture), tmpDir.name);
}

return tmpDir.name;
}

export {bootstrap};
48 changes: 0 additions & 48 deletions @packages/test/src/git.js

This file was deleted.

34 changes: 34 additions & 0 deletions @packages/test/src/git.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import execa from 'execa';

import * as fix from './fix';

export async function bootstrap(fixture?: string) {
const cwd = await fix.bootstrap(fixture);

await init(cwd);
return cwd;
}

export async function clone(source: string, ...args: string[]) {
const cwd = await fix.bootstrap();

await execa('git', ['clone', ...args, source, cwd]);
await setup(cwd);
return cwd;
}

export async function init(cwd: string) {
await execa('git', ['init', cwd]);
await setup(cwd);
return cwd;
}

async function setup(cwd: string) {
try {
await execa('git', ['config', 'user.name', 'ava'], {cwd});
await execa('git', ['config', 'user.email', '[email protected]'], {cwd});
await execa('git', ['config', 'commit.gpgsign', 'false'], {cwd});
} catch (err) {
console.warn(`git config in ${cwd} failed`, err.message);
}
}
14 changes: 0 additions & 14 deletions @packages/test/src/index.test.js

This file was deleted.

32 changes: 32 additions & 0 deletions @packages/test/src/index.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import * as u from '.';
import os from 'os';
import path from 'path';
import fs from 'fs-extra';

test('exports a git namespace', () => {
expect(typeof u.git).toBe('object');
});

test('git namespace has bootstrap', () => {
expect(typeof u.git.bootstrap).toBe('function');
});

test('git namespace has clone', () => {
expect(typeof u.git.clone).toBe('function');
});

test('expect to create tmp directory', async () => {
const directory = await u.git.bootstrap();
expect(directory).toContain('tmp-');
expect(directory).toContain(os.tmpdir());
});

test('expect to create tmp from directory from src', async () => {
const directory = await u.git.bootstrap('.github');
expect(directory).toContain('tmp-');
expect(directory).toContain(os.tmpdir());
expect(fs.existsSync(directory)).toBeTruthy();

const indexFile = path.join(directory, 'ISSUE_TEMPLATE.md');
expect(fs.existsSync(indexFile)).toBeTruthy();
});
File renamed without changes.
9 changes: 4 additions & 5 deletions @packages/test/src/npm.js → @packages/test/src/npm.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
import execa from 'execa';
import * as sander from '@marionebl/sander';
import path from 'path';
import fs from 'fs-extra';

import * as git from './git';

export {bootstrap};

async function bootstrap(fixture) {
export async function bootstrap(fixture: string) {
const cwd = await git.bootstrap(fixture);

if (await sander.exists(cwd, 'package.json')) {
if (await fs.pathExists(path.join(cwd, 'package.json'))) {
await execa('npm', ['install'], {cwd});
}

Expand Down
15 changes: 15 additions & 0 deletions @packages/test/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"extends": "../../tsconfig.shared.json",
"compilerOptions": {
"composite": true,
"rootDir": "./src",
"outDir": "./lib"
},
"include": [
"./src"
],
"exclude": [
"./src/**/*.test.ts",
"./lib/**/*"
]
}
1 change: 1 addition & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"include": [],
"extends": "./tsconfig.shared.json",
"references": [
{ "path": "@packages/test" },
{ "path": "@commitlint/ensure" },
{ "path": "@commitlint/execute-rule" },
{ "path": "@commitlint/format" },
Expand Down
Loading