Skip to content

Commit 1121614

Browse files
committedNov 10, 2015
Merge pull request #39 from js-data/develop
Refactored core adapter tests into a re-usable, standalone repo.
·
1.0.10.11.6
2 parents 5d22b9b + 2428892 commit 1121614

File tree

9 files changed

+30
-523
lines changed

9 files changed

+30
-523
lines changed
 

‎mocha.start.js

Lines changed: 27 additions & 115 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,20 @@
11
/*global assert:true */
22
'use strict';
33

4-
var assert = require('chai').assert;
5-
assert.equalObjects = function (a, b, m) {
6-
assert.deepEqual(JSON.parse(JSON.stringify(a)), JSON.parse(JSON.stringify(b)), m || 'Objects should be equal!');
7-
};
4+
var JSData = require('js-data');
5+
var TestRunner = require('js-data-adapter-tests');
6+
87
var mocha = require('mocha');
98
var coMocha = require('co-mocha');
9+
1010
coMocha(mocha);
11-
var JSData = require('js-data');
1211
JSData.DSUtils.Promise = require('bluebird');
13-
var DSSqlAdapter = require('./');
1412

15-
var adapter, store, DSUtils, DSErrors, Profile, User, Post, Comment;
13+
var DSSqlAdapter = require('./');
1614

1715
var globals = module.exports = {
18-
fail: function (msg) {
19-
assert.equal('should not reach this!: ' + msg, 'failure');
20-
},
21-
TYPES_EXCEPT_STRING: [123, 123.123, null, undefined, {}, [], true, false, function () {
22-
}],
23-
TYPES_EXCEPT_STRING_OR_ARRAY: [123, 123.123, null, undefined, {}, true, false, function () {
24-
}],
25-
TYPES_EXCEPT_STRING_OR_NUMBER: [null, undefined, {}, [], true, false, function () {
26-
}],
27-
TYPES_EXCEPT_STRING_OR_OBJECT: [123, 123.123, null, undefined, [], true, false, function () {
28-
}],
29-
TYPES_EXCEPT_STRING_OR_NUMBER_OBJECT: [null, undefined, [], true, false, function () {
30-
}],
31-
TYPES_EXCEPT_STRING_OR_ARRAY_OR_NUMBER: [null, undefined, {}, true, false, function () {
32-
}],
33-
TYPES_EXCEPT_NUMBER: ['string', null, undefined, {}, [], true, false, function () {
34-
}],
35-
TYPES_EXCEPT_OBJECT: ['string', 123, 123.123, null, undefined, true, false, function () {
36-
}],
37-
TYPES_EXCEPT_BOOLEAN: ['string', 123, 123.123, null, undefined, {}, [], function () {
38-
}],
39-
TYPES_EXCEPT_FUNCTION: ['string', 123, 123.123, null, undefined, {}, [], true, false],
40-
assert: assert,
41-
adapter: undefined,
16+
TestRunner: TestRunner,
17+
assert: TestRunner.assert,
4218
co: require('co')
4319
};
4420

@@ -52,91 +28,27 @@ for (var key in globals) {
5228
}
5329
test.globals(testGlobals);
5430

55-
beforeEach(function () {
56-
store = new JSData.DS({
57-
log: false
58-
});
59-
adapter = new DSSqlAdapter({
60-
client: 'mysql',
61-
connection: {
62-
host: process.env.DB_HOST || 'localhost',
63-
user: process.env.DB_USER || process.env.C9_USER || 'ubuntu',
64-
database: process.env.DB_NAME || (process.env.C9_USER ? 'c9' : 'circle_test')
65-
//user: 'root',
66-
//database: 'test'
67-
}
68-
});
69-
DSUtils = JSData.DSUtils;
70-
DSErrors = JSData.DSErrors;
71-
globals.Profile = global.Profile = Profile = store.defineResource({
72-
name: 'profile'
73-
});
74-
globals.User = global.User = User = store.defineResource({
75-
name: 'user',
76-
relations: {
77-
hasMany: {
78-
post: {
79-
localField: 'posts',
80-
foreignKey: 'post'
81-
}
82-
},
83-
hasOne: {
84-
profile: {
85-
localField: 'profile',
86-
localKey: 'profileId'
87-
}
88-
}
89-
}
90-
});
91-
globals.Post = global.Post = Post = store.defineResource({
92-
name: 'post',
93-
relations: {
94-
belongsTo: {
95-
user: {
96-
localField: 'user',
97-
localKey: 'userId'
98-
}
99-
},
100-
hasMany: {
101-
comment: {
102-
localField: 'comments',
103-
foreignKey: 'postId'
104-
}
105-
}
106-
}
107-
});
108-
globals.Comment = global.Comment = Comment = store.defineResource({
109-
name: 'comment',
110-
relations: {
111-
belongsTo: {
112-
post: {
113-
localField: 'post',
114-
localKey: 'postId'
115-
},
116-
user: {
117-
localField: 'user',
118-
localKey: 'userId'
119-
}
120-
}
121-
}
122-
});
123-
124-
globals.adapter = adapter;
125-
global.adapter = globals.adapter;
126-
127-
globals.DSUtils = DSUtils;
128-
global.DSUtils = globals.DSUtils;
31+
var config = {
32+
client: 'mysql',
33+
connection: {
34+
host: process.env.DB_HOST || 'localhost',
35+
user: process.env.DB_USER || process.env.C9_USER || 'ubuntu',
36+
database: process.env.DB_NAME || (process.env.C9_USER ? 'c9' : 'circle_test')
37+
}
38+
};
12939

130-
globals.DSErrors = DSErrors;
131-
global.DSErrors = globals.DSErrors;
40+
TestRunner.init({
41+
DS: JSData.DS,
42+
Adapter: DSSqlAdapter,
43+
adapterConfig: config
13244
});
13345

134-
afterEach(function* () {
135-
globals.adapter = null;
136-
global.adapter = null;
137-
138-
yield adapter.destroyAll(Comment);
139-
yield adapter.destroyAll(Post);
140-
yield adapter.destroyAll(User);
141-
yield adapter.destroyAll(Profile);
46+
beforeEach(function () {
47+
globals.DSUtils = global.DSUtils = this.$$DSUtils
48+
globals.DSErrors = global.DSErrors = this.$$DSErrors
49+
globals.adapter = global.adapter = this.$$adapter
50+
globals.User = global.User = this.$$User
51+
globals.Profile = global.Profile = this.$$Profile;
52+
globals.Post = global.Post = this.$$Post;
53+
globals.Comment = global.Comment = this.$$Comment;
14254
});

‎package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,13 @@
3030
"babel-eslint": "4.1.3",
3131
"babel-loader": "5.3.2",
3232
"bluebird": "2.10.2",
33-
"chai": "3.3.0",
33+
"chai": "3.4.1",
3434
"co": "4.6.0",
3535
"co-mocha": "1.1.2",
3636
"codacy-coverage": "1.1.3",
3737
"coveralls": "2.11.4",
3838
"istanbul": "0.4.0",
39+
"js-data-adapter-tests": "~1.x",
3940
"mocha": "2.3.3",
4041
"standard": "5.3.1",
4142
"webpack": "1.12.2"
@@ -55,7 +56,7 @@
5556
"mout": "0.11.0"
5657
},
5758
"peerDependencies": {
58-
"js-data": ">=2.0.0",
59+
"js-data": "~2.x",
5960
"knex": ">=0.7.4"
6061
}
6162
}

‎test/create.spec.js

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

‎test/destroy.spec.js

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

‎test/destroyAll.spec.js

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

‎test/find.spec.js

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

‎test/findAll.spec.js

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

‎test/update.spec.js

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

‎test/updateAll.spec.js

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

0 commit comments

Comments
 (0)
Please sign in to comment.