Skip to content

Commit

Permalink
Add TypeScript consumer tests - to test the importing of the library …
Browse files Browse the repository at this point in the history
…using TypeScript with type annotations
  • Loading branch information
steveukx committed May 30, 2020
1 parent 7d90127 commit e767fd3
Show file tree
Hide file tree
Showing 15 changed files with 1,345 additions and 52 deletions.
24 changes: 24 additions & 0 deletions babel.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
const joinPaths = require('path').join;

module.exports = {
presets: [
[
'@babel/preset-env',
{
targets: {
node: 'current',
},
},
],
'@babel/preset-typescript',
],
plugins: [
['module-resolver', {
root: '.',
alias: {
'simple-git': __dirname,
// 'simple-git/promise': joinPaths(__dirname, 'promise'),
},
}],
],
};
12 changes: 7 additions & 5 deletions jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,6 @@ module.exports = {
"<rootDir>/src/",
"<rootDir>/test/",
],
transform: {
'^.+\\.tsx?$': 'ts-jest'
},
coverageThreshold: {
global: {
branches: 80,
Expand All @@ -17,6 +14,11 @@ module.exports = {
coverageReporters: ['json', 'lcov', 'text', 'clover'],
testMatch: [
"**/test/**/test-*.js",
"**/test/**/*.spec.js"
]
"**/test/**/*.spec.*"
],
globals: {
'ts-jest': {
tsConfig: 'tsconfig.test.json'
}
}
};
14 changes: 8 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,20 @@
"email": "[email protected]"
}
],
"dependencies": {
"@kwsites/exec-p": "^0.4.0",
"debug": "^4.0.1"
},
"dependencies": {},
"devDependencies": {
"@babel/core": "^7.10.1",
"@babel/preset-env": "^7.10.1",
"@babel/preset-typescript": "^7.10.1",
"@kwsites/jestify-node-unit": "^1.0.1",
"@types/jest": "^25.2.1",
"@types/jest": "^25.2.3",
"@types/node": "^13.11.1",
"babel-jest": "^26.0.1",
"babel-plugin-module-resolver": "^4.0.0",
"jest": "^25.3.0",
"sinon": "^7.3.2",
"ts-jest": "^25.4.0",
"ts-node": "^8.8.2",
"ts-node": "^8.10.2",
"typescript": "^3.8.3"
},
"keywords": [
Expand Down
1 change: 0 additions & 1 deletion src/git.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
var debug = require('debug')('simple-git');
var exists = require('./util/exists');
var responses = require('./responses');

Expand Down
35 changes: 35 additions & 0 deletions test/consumer/ts-promise-consumer.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// @ts-ignore
import gitP, { CleanOptions, CleanSummary, SimpleGit, TaskConfigurationError } from 'simple-git/promise';

const Test: any = require('../integration/include/runner');

describe('TS Promise Consumer', () => {

let context: any;

beforeEach(() => context = Test.createContext());

it('imports', () => {
expect(typeof gitP).toBe('function');
expect(CleanOptions).toEqual(expect.objectContaining({
'FORCE': 'f',
}));
});

it('finds types, enums and errors', async () => {
const git: SimpleGit = gitP(context.root);
await git.init();
await context.fileP('file.txt', 'content');

const error: TaskConfigurationError | CleanSummary = await git.clean(CleanOptions.DRY_RUN, ['--interactive'])
.catch((e: TaskConfigurationError) => e);
expect(error).toBeInstanceOf(Error);

const clean: CleanSummary = await git.clean(CleanOptions.FORCE);
expect(clean).toEqual(expect.objectContaining({
dryRun: false,
files: ['file.txt'],
}));
});

});
35 changes: 35 additions & 0 deletions test/consumer/ts-root-consumer.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// @ts-ignore
import { gitP, CleanOptions, CleanSummary, SimpleGit, TaskConfigurationError } from 'simple-git';

const Test: any = require('../integration/include/runner');

describe('TS Root Consumer', () => {

let context: any;

beforeEach(() => context = Test.createContext());

it('imports', () => {
expect(typeof gitP).toBe('function');
expect(CleanOptions).toEqual(expect.objectContaining({
'FORCE': 'f',
}));
});

it('finds types, enums and errors', async () => {
const git: SimpleGit = gitP(context.root);
await git.init();
await context.fileP('file.txt', 'content');

const error: TaskConfigurationError | CleanSummary = await git.clean(CleanOptions.DRY_RUN, ['--interactive'])
.catch((e: TaskConfigurationError) => e);
expect(error).toBeInstanceOf(Error);

const clean: CleanSummary = await git.clean(CleanOptions.FORCE);
expect(clean).toEqual(expect.objectContaining({
dryRun: false,
files: ['file.txt'],
}));
});

});
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const Test = require('./include/runner');

describe('branches', () => {
describe('config', () => {

let context, git;

Expand Down
File renamed without changes.
File renamed without changes.
19 changes: 9 additions & 10 deletions test/integration/test-tag.js → test/integration/tag.spec.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,18 @@
const Test = require('./include/runner');

const setUp = (context) => {
const repo = context.gitP(context.root);

return repo.init()
.then(() => context.file('foo', 'bar', 'content'))
.then(() => repo.add('foo/*'))
.then(() => repo.commit('message'));
};

describe('tag', () => {

let context;

beforeEach(() => setUp(context = Test.createContext()));
beforeEach(async () => {
context = Test.createContext();

const git = context.gitP(context.root);
await git.init();
await context.fileP('foo', 'bar', 'content');
await git.add('foo/*');
await git.commit('message');
});

it('creates a named tag without the need for a callback', () => {
const {git, gitP, root} = context;
Expand Down
2 changes: 1 addition & 1 deletion test/unit/test-clean.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ describe('clean', () => {

it('cleans with options and multiple paths', async () => {
closeWith('');
await git.clean(CleanOptions.IGNORED + CleanOptions.FORCE, {'./path-1': null, './path-2': null});
await git.clean(CleanOptions.IGNORED_ONLY + CleanOptions.FORCE, {'./path-1': null, './path-2': null});
expect(theCommandRun()).toEqual(['clean', '-f', '-X', './path-1', './path-2']);
});

Expand Down
2 changes: 2 additions & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
"forceConsistentCasingInFileNames": true,
"baseUrl": ".",
"paths": {
"simple-git": ["."],
"simple-git/promise": ["./promise"]
},

"composite": true,
Expand Down
Loading

0 comments on commit e767fd3

Please sign in to comment.