Skip to content

Commit 036ecaa

Browse files
committed
Move tests in lib
1 parent 0497f76 commit 036ecaa

27 files changed

+182
-229
lines changed

.eslintrc

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,11 @@
1313
"env": {
1414
"node": true,
1515
"mocha": true,
16-
"browser": false
16+
"browser": false,
17+
"jasmine": true
18+
},
19+
"globals": {
20+
"fixtures": true
1721
},
1822
"extends": "eslint:recommended"
1923
}

README.md

Lines changed: 4 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,6 @@ $ npm install gitkit
1212

1313
## Usage
1414

15-
#### Examples
16-
17-
| Example | Description |
18-
| ------- | ----------- |
19-
| [Clone](./examples/clone.js) | Clone a remote git repository |
20-
2115
#### API
2216

2317
```js
@@ -31,21 +25,12 @@ var fs = NodeFS(process.cwd());
3125
var repo = Repository.createWithFS(fs, isBare);
3226
```
3327

34-
#### Command line Usage
35-
36-
```
37-
# List commits on the current branch
38-
$ gitkit log
39-
40-
# List entries in a tree
41-
$ gitkit ls-tree [sha]
28+
#### Examples
4229

43-
# Print an object (blob / tree / commit)
44-
$ gitkit cat-file [sha]
30+
| Example | Description |
31+
| ------- | ----------- |
32+
| [Clone](./examples/clone.js) | Clone a remote git repository |
4533

46-
# List all files in working directory
47-
$ gitkit ls-files
48-
```
4934

5035
## Thanks
5136

test/applyDelta.js renamed to lib/TransferUtils/__tests__/applyDelta.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
var Buffer = require('buffer').Buffer;
2-
var applyDelta = require('../lib/TransferUtils/applyDelta');
2+
var applyDelta = require('../applyDelta');
33

44
var DELTA = 'mwKaApA1KGQyNWNhMjVhYWJmOTkzZTg1MjdkN2I4NGFhNjMxODkxZjJlZWVmNDiRXUAFMDY5NTORokouMDY5NTMzIC0wODAwCgphZGQgYXNzZXJ0LmVuZCgpIHRvIHV0aWxzIHRlc3RzCg==';
55
var BASE = 'dHJlZSA0YWRlOTdjMTgxMjNjNTdhNTBlM2I5OTIzZDA1M2ZkMmRiNGY2MDVmCnBhcmVudCA3N2ZlMTg0OTRiNGI3ZWJmMGVjY2E0ZDBjY2Y4NTA3M2ZiMjFiZGZiCmF1dGhvciBDaHJpcyBEaWNraW5zb24gPGNocmlzdG9waGVyLnMuZGlja2luc29uQGdtYWlsLmNvbT4gMTM1NjY1NDMwMyAtMDgwMApjb21taXR0ZXIgQ2hyaXMgRGlja2luc29uIDxjaHJpc3RvcGhlci5zLmRpY2tpbnNvbkBnbWFpbC5jb20+IDEzNTY2NTQzMDMgLTA4MDAKCmJ1bXAgdmVyc2lvbiBmb3IgY2kudGVzdGxpbmcuY29tCg==';
@@ -12,6 +12,6 @@ describe('applyDelta', function() {
1212
var base = new Buffer(BASE, 'base64');
1313

1414
var out = applyDelta(base, delta);
15-
out.toString('base64').should.equal(OUTPUT);
15+
expect(out.toString('base64'), OUTPUT);
1616
});
1717
});
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
var parseDiscovery = require('../parseDiscovery');
2+
3+
describe('parseDiscovery', function() {
4+
it('should parse capabilities and refs', function() {
5+
var stream = fixtures.createReadStream('discovery-http-output');
6+
7+
return parseDiscovery(
8+
stream
9+
)
10+
.then(function(out) {
11+
expect(out).toExist();
12+
expect(out.capabilities).toExist();
13+
expect(out.capabilities).toEqual([
14+
'multi_ack',
15+
'thin-pack',
16+
'side-band',
17+
'side-band-64k',
18+
'ofs-delta',
19+
'shallow',
20+
'no-progress',
21+
'include-tag',
22+
'multi_ack_detailed',
23+
'no-done',
24+
'symref=HEAD:refs/heads/master',
25+
'agent=git/2:2.6.5+github-1394-g163a735'
26+
]);
27+
28+
expect(out.refs).toExist();
29+
expect(out.refs.size).toBe(422);
30+
31+
expect(out.refs.get('HEAD').getCommit()).toBe('ba182ce8e430f08bd8c60865b9c853875a3d6483');
32+
expect(out.refs.get('refs/heads/master').getCommit()).toBe('ba182ce8e430f08bd8c60865b9c853875a3d6483');
33+
expect(out.refs.get('refs/tags/2.5.1').getCommit()).toBe('3388be9db6c6ae2173652df20eb98f36186c1f9a');
34+
});
35+
});
36+
});
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
var parsePack = require('../parsePack');
2+
3+
describe('parsePack', function() {
4+
it('should output all objects', function(done) {
5+
var packCount = 0;
6+
7+
fixtures.createReadStream('pack')
8+
.pipe(parsePack())
9+
.on('data', function(line) {
10+
packCount++;
11+
})
12+
.on('error', function(err) {
13+
done(err);
14+
})
15+
.on('finish', function() {
16+
expect(packCount).toBe(481);
17+
18+
done();
19+
});
20+
});
21+
});

test/parsePktLines.js renamed to lib/TransferUtils/__tests__/parsePktLines.js

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,20 @@
1-
var should = require('should');
21
var intoStream = require('into-stream');
32

4-
var parsePktLines = require('../lib/TransferUtils/parsePktLines');
5-
var parsePktLineMeta = require('../lib/TransferUtils/parsePktLineMeta');
6-
var fixtures = require('./fixtures');
3+
var parsePktLines = require('../parsePktLines');
4+
var parsePktLineMeta = require('../parsePktLineMeta');
75

86
var data = [
97
'001bhi\0ofs-delta hat party\n',
108
'0007hi\n',
119
'0032want 0000000000000000000000000000000000000000\n',
1210
'0000'
13-
//'PACK0123456678999'
1411
];
1512

16-
var expect = [
13+
var results = [
1714
{data:'hi\n', type:'pkt-line', caps:['ofs-delta', 'hat', 'party']},
1815
{data:'hi\n', type:'pkt-line', caps:['ofs-delta', 'hat', 'party']},
1916
{data:'want 0000000000000000000000000000000000000000\n', type:'pkt-line', caps:['ofs-delta', 'hat', 'party']},
2017
{data:'', type:'pkt-flush', caps:['ofs-delta', 'hat', 'party']}
21-
//{size:17, data:'PACK0123456678999', type:'packfile', caps:['ofs-delta', 'hat', 'party']}
2218
];
2319

2420
describe('parsePktLines and parsePktLineMeta', function() {
@@ -29,16 +25,16 @@ describe('parsePktLines and parsePktLineMeta', function() {
2925
.pipe(parsePktLines())
3026
.pipe(parsePktLineMeta())
3127
.on('data', function(line) {
32-
var expectLine = expect[lineIdx];
28+
var expectLine = results[lineIdx];
3329

34-
line.toString('utf8').should.equal(expectLine.data);
35-
line.type.should.equal(expectLine.type);
36-
should(line.caps).deepEqual(expectLine.caps);
30+
expect(line.toString('utf8')).toBe(expectLine.data);
31+
expect(line.type).toBe(expectLine.type);
32+
expect(line.caps).toEqual(expectLine.caps);
3733

3834
lineIdx++;
3935
})
4036
.on('finish', function() {
41-
lineIdx.should.equal(expect.length);
37+
expect(lineIdx).toBe(results.length);
4238

4339
done();
4440
});
@@ -53,7 +49,7 @@ describe('parsePktLines and parsePktLineMeta', function() {
5349
count++;
5450
})
5551
.on('finish', function() {
56-
count.should.equal(425);
52+
expect(count).toBe(425);
5753

5854
done();
5955
});
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
var parseUploadPack = require('../parseUploadPack');
2+
3+
describe('parseUploadPack', function() {
4+
this.timeout(3000000);
5+
6+
it('should output all lines', function(done) {
7+
var objectCount = 0;
8+
9+
fixtures.createReadStream('pack-http-output')
10+
.pipe(parseUploadPack())
11+
.on('data', function() {
12+
objectCount++;
13+
})
14+
.on('error', function(err) {
15+
done(err);
16+
})
17+
.on('finish', function() {
18+
expect(objectCount).toBe(12545);
19+
20+
done();
21+
});
22+
});
23+
});
Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
1-
var Git = require('../');
1+
var Blob = require('../blob');
22

33
describe('Blob', function() {
4-
54
describe('.createFromString', function() {
65
it('should create a blob', function() {
7-
var blob = Git.Blob.createFromString('Hello World');
8-
blob.should.be.an.instanceOf(Git.Blob);
6+
var blob = Blob.createFromString('Hello World');
7+
expect(blob).toBeA(Blob);
98
});
109
});
11-
1210
});
1311

lib/models/__tests__/object.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
var GitObject = require('../object');
2+
3+
describe('Object', function() {
4+
describe('.createFromBuffer', function() {
5+
it('should read tree', function() {
6+
var buf = fixtures.read('object-tree');
7+
var obj = GitObject.createFromZip(buf);
8+
9+
expect(obj.getContent().length).toBe(352);
10+
expect(obj.getType()).toBe(GitObject.TYPES.TREE);
11+
});
12+
});
13+
});

lib/models/__tests__/tree.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
var GitObject = require('../object');
2+
var Tree = require('../tree');
3+
4+
describe('Tree', function() {
5+
it('.createFromBuffer', function() {
6+
var buf = fixtures.read('object-tree');
7+
8+
var obj = GitObject.createFromZip(buf);
9+
var tree = Tree.createFromBuffer(obj.getContent());
10+
11+
var entries = tree.getEntries();
12+
expect(entries.size).toBe(10);
13+
});
14+
});
Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,14 @@
1-
var Git = require('../');
2-
var fixtures = require('./fixtures');
1+
var WorkingIndex = require('../workingIndex');
32

43
describe('WorkingIndex', function() {
5-
64
it('.createFromBuffer', function() {
75
var buf = fixtures.read('index');
8-
var wk = Git.WorkingIndex.createFromBuffer(buf);
6+
var wk = WorkingIndex.createFromBuffer(buf);
97

108
var version = wk.getVersion();
119
var entries = wk.getEntries();
1210

13-
version.should.equal(2);
14-
entries.size.should.equal(94);
11+
expect(version).toBe(2);
12+
expect(entries.size).toBe(94);
1513
});
16-
1714
});

package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,14 @@
3434
},
3535
"devDependencies": {
3636
"eslint": "^2.7.0",
37+
"expect": "^1.19.0",
3738
"into-stream": "^2.0.0",
3839
"mocha": "2.3.4",
3940
"should": "^8.0.1"
4041
},
4142
"scripts": {
42-
"test": "node_modules/.bin/mocha -b --reporter spec --bail --timeout 15000 ./test/all.js"
43+
"test": "./node_modules/.bin/mocha ./test/setup.js ./lib/**/*/__tests__/*.js --bail --reporter=list",
44+
"lint": "eslint ."
4345
},
4446
"bin": {
4547
"gitkit": "./bin/git.js"

test/RepoUtils.js

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

test/all.js

Lines changed: 0 additions & 16 deletions
This file was deleted.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

test/fixtures.js

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
var fs = require('fs');
2+
var path = require('path');
3+
4+
/*
5+
Return path to a fixture
6+
7+
@param {String}
8+
@return {String}
9+
*/
10+
function fixturePath(name) {
11+
return path.resolve(__dirname, 'data', name);
12+
}
13+
14+
15+
/*
16+
Read a fixture as a stream
17+
18+
@param {String}
19+
@return {Stream}
20+
*/
21+
function createReadStream(name) {
22+
return fs.createReadStream(fixturePath(name));
23+
}
24+
25+
/*
26+
Read a fixture as a buffer
27+
28+
@param {String}
29+
@return {Buffer}
30+
*/
31+
function read(name) {
32+
return fs.readFileSync(fixturePath(name));
33+
}
34+
35+
module.exports = {
36+
path: fixturePath,
37+
read: read,
38+
createReadStream: createReadStream
39+
};

test/mock.js

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

0 commit comments

Comments
 (0)