Skip to content

Commit 4c292df

Browse files
authored
1 parent 0241ad5 commit 4c292df

File tree

18 files changed

+5769
-3109
lines changed

18 files changed

+5769
-3109
lines changed

.eslintrc.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,5 @@ module.exports = {
1010
},
1111
]
1212
},
13-
env: { mocha: true }
13+
env: { jest: true }
1414
}

.npmignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
src
2-
test
2+
__tests__
3+
__fixtures__
Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@ const serverReady = require('server-ready')
1212
let PORT = 3100
1313

1414
const middlewareFiles = {
15-
en: './fixtures/middlewares/en.js',
16-
jp: './fixtures/middlewares/jp.js',
17-
postbody: './fixtures/middlewares/postbody.js'
15+
en: './../../__fixtures__/middlewares/en.js',
16+
jp: './../../__fixtures__/middlewares/jp.js',
17+
postbody: './../../__fixtures__/middlewares/postbody.js'
1818
}
1919

2020
const bin = path.join(__dirname, '../../lib/cli/bin')
@@ -60,11 +60,11 @@ describe('cli', () => {
6060
serverReady(PORT, done)
6161
})
6262

63-
it('should support JSON file', done => {
63+
test('should support JSON file', done => {
6464
request.get('/posts').expect(200, done)
6565
})
6666

67-
it('should send CORS headers', done => {
67+
test('should send CORS headers', done => {
6868
const origin = 'http://example.com'
6969

7070
request
@@ -74,7 +74,7 @@ describe('cli', () => {
7474
.expect(200, done)
7575
})
7676

77-
it('should update JSON file', done => {
77+
test('should update JSON file', done => {
7878
request
7979
.post('/posts')
8080
.send({ title: 'hello' })
@@ -90,11 +90,11 @@ describe('cli', () => {
9090

9191
describe('seed.js', () => {
9292
beforeEach(done => {
93-
child = cli(['fixtures/seed.js'])
93+
child = cli(['../../__fixtures__/seed.js'])
9494
serverReady(PORT, done)
9595
})
9696

97-
it('should support JS file', done => {
97+
test('should support JS file', done => {
9898
request.get('/posts').expect(200, done)
9999
})
100100
})
@@ -105,7 +105,7 @@ describe('cli', () => {
105105
serverReady(PORT, done)
106106
})
107107

108-
it('should support URL file', done => {
108+
test('should support URL file', done => {
109109
request.get('/posts').expect(200, done)
110110
})
111111
})
@@ -127,20 +127,20 @@ describe('cli', () => {
127127
serverReady(PORT, done)
128128
})
129129

130-
it('should use routes.json and _id as the identifier', done => {
130+
test('should use routes.json and _id as the identifier', done => {
131131
request.get('/blog/posts/2').expect(200, done)
132132
})
133133

134-
it('should use _id as foreignKeySuffix', async () => {
134+
test('should use _id as foreignKeySuffix', async () => {
135135
const response = await request.get('/posts/1/comments')
136136
assert.equal(response.body.length, 1)
137137
})
138138

139-
it('should apply middlewares', done => {
139+
test('should apply middlewares', done => {
140140
request.get('/blog/posts/2').expect('X-Hello', 'World', done)
141141
})
142142

143-
it('should allow only GET requests', done => {
143+
test('should allow only GET requests', done => {
144144
request.post('/blog/posts').expect(403, done)
145145
})
146146
})
@@ -151,7 +151,7 @@ describe('cli', () => {
151151
serverReady(PORT, done)
152152
})
153153

154-
it('should apply all middlewares', done => {
154+
test('should apply all middlewares', done => {
155155
request
156156
.get('/posts')
157157
.expect('X-Hello', 'World')
@@ -165,7 +165,7 @@ describe('cli', () => {
165165
serverReady(PORT, done)
166166
})
167167

168-
it('should have post body in middleware', done => {
168+
test('should have post body in middleware', done => {
169169
request
170170
.post('/posts')
171171
.send({ name: 'test' })
@@ -179,7 +179,7 @@ describe('cli', () => {
179179
serverReady(PORT, done)
180180
})
181181

182-
it('should delay response', done => {
182+
test('should delay response', done => {
183183
const start = new Date()
184184
request.get('/posts').expect(200, function(err) {
185185
const end = new Date()
@@ -188,9 +188,9 @@ describe('cli', () => {
188188
})
189189
})
190190

191-
describe('db.json -s fixtures/public -S /some/path/snapshots', () => {
191+
describe('db.json -s ../../__fixtures__/public -S /some/path/snapshots', () => {
192192
const snapshotsDir = path.join(osTmpdir(), 'snapshots')
193-
const publicDir = 'fixtures/public'
193+
const publicDir = '../../__fixtures__/public'
194194

195195
beforeEach(done => {
196196
rimraf.sync(snapshotsDir)
@@ -203,22 +203,22 @@ describe('cli', () => {
203203
})
204204
})
205205

206-
it('should serve fixtures/public', done => {
206+
test('should serve ../../__fixtures__/public', done => {
207207
request.get('/').expect(/Hello/, done)
208208
})
209209

210-
it('should save a snapshot in snapshots dir', () => {
210+
test('should save a snapshot in snapshots dir', () => {
211211
assert.equal(fs.readdirSync(snapshotsDir).length, 1)
212212
})
213213
})
214214

215-
describe('fixtures/seed.json --no-cors=true', () => {
215+
describe('../../__fixtures__/seed.json --no-cors=true', () => {
216216
beforeEach(done => {
217-
child = cli(['fixtures/seed.js', '--no-cors=true'])
217+
child = cli(['../../__fixtures__/seed.js', '--no-cors=true'])
218218
serverReady(PORT, done)
219219
})
220220

221-
it('should not send Access-Control-Allow-Origin headers', done => {
221+
test('should not send Access-Control-Allow-Origin headers', done => {
222222
const origin = 'http://example.com'
223223

224224
request
@@ -238,13 +238,13 @@ describe('cli', () => {
238238
})
239239
})
240240

241-
describe('fixtures/seed.json --no-gzip=true', () => {
241+
describe('../../__fixtures__/seed.json --no-gzip=true', () => {
242242
beforeEach(done => {
243-
child = cli(['fixtures/seed.js', '--no-gzip=true'])
243+
child = cli(['../../__fixtures__/seed.js', '--no-gzip=true'])
244244
serverReady(PORT, done)
245245
})
246246

247-
it('should not set Content-Encoding to gzip', done => {
247+
test('should not set Content-Encoding to gzip', done => {
248248
request
249249
.get('/posts')
250250
.expect(200)
@@ -266,14 +266,14 @@ describe('cli', () => {
266266
serverReady(PORT, done)
267267
})
268268

269-
it('should watch db file', done => {
269+
test('should watch db file', done => {
270270
fs.writeFileSync(dbFile, JSON.stringify({ foo: [] }))
271271
setTimeout(() => {
272272
request.get('/foo').expect(200, done)
273273
}, 1000)
274274
})
275275

276-
it('should watch routes file', done => {
276+
test('should watch routes file', done => {
277277
fs.writeFileSync(routesFile, JSON.stringify({ '/api/*': '/$1' }))
278278
setTimeout(() => {
279279
request.get('/api/posts').expect(200, done)
@@ -288,7 +288,7 @@ describe('cli', () => {
288288
serverReady(PORT, done)
289289
})
290290

291-
it("should create JSON file if it doesn't exist", done => {
291+
test("should create JSON file if it doesn't exist", done => {
292292
request.get('/posts').expect(200, done)
293293
})
294294
})
@@ -298,7 +298,7 @@ describe('cli', () => {
298298
dbFile = tempWrite.sync(JSON.stringify({ 'a/b': [] }), 'db-error.json')
299299
})
300300

301-
it('should exit with an error', done => {
301+
test('should exit with an error', done => {
302302
child = cli([dbFile])
303303
child.on('exit', code => {
304304
if (code === 1) {
Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ const mixins = require('../../src/server/mixins')
66
describe('mixins', () => {
77
let db
88

9-
before(() => {
9+
beforeAll(() => {
1010
_.mixin(lodashId)
1111
_.mixin(mixins)
1212
})
@@ -25,7 +25,7 @@ describe('mixins', () => {
2525
})
2626

2727
describe('getRemovable', () => {
28-
it('should return removable documents', () => {
28+
test('should return removable documents', () => {
2929
const expected = [
3030
{ name: 'comments', id: 2 },
3131
{ name: 'comments', id: 3 }
@@ -34,7 +34,7 @@ describe('mixins', () => {
3434
assert.deepEqual(_.getRemovable(db, { foreignKeySuffix: 'Id' }), expected)
3535
})
3636

37-
it('should support custom foreignKeySuffix', () => {
37+
test('should support custom foreignKeySuffix', () => {
3838
const expected = [
3939
{ name: 'comments', id: 2 },
4040
{ name: 'comments', id: 3 }
@@ -45,11 +45,11 @@ describe('mixins', () => {
4545
})
4646

4747
describe('createId', () => {
48-
it('should return a new id', () => {
48+
test('should return a new id', () => {
4949
assert.equal(_.createId(db.comments), 4)
5050
})
5151

52-
it('should return a new uuid', () => {
52+
test('should return a new uuid', () => {
5353
assert.notEqual(_.createId(db.photos), 3)
5454
})
5555
})

0 commit comments

Comments
 (0)