Skip to content

Commit 39f615c

Browse files
authored
Accept .cjs (Commonjs) file for the db (#1368)
1 parent 7310b2b commit 39f615c

File tree

3 files changed

+49
-1
lines changed

3 files changed

+49
-1
lines changed

__fixtures__/seed.cjs

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
// Need some fake data for the gzip test to work
2+
module.exports = function () {
3+
return {
4+
posts: [
5+
{
6+
id: 1,
7+
content:
8+
"Oh! The garbage chute was a really wonderful idea. What an incredible smell you've discovered! Let's get out of here! Get away from there... No! wait! Will you forget it? I already tried it. It's magnetically sealed! Put that thing away! You're going to get us all killed. Absolutely, Your Worship. Look, I had everything under control until you led us down here. You know, it's not going to take them long to figure out what happened to us. It could be worst... It's worst. There's something alive in here! That's your imagination. Something just moves past my leg! Look! Did you see that? What? Help!",
9+
},
10+
{
11+
id: 2,
12+
content:
13+
"Oh! The garbage chute was a really wonderful idea. What an incredible smell you've discovered! Let's get out of here! Get away from there... No! wait! Will you forget it? I already tried it. It's magnetically sealed! Put that thing away! You're going to get us all killed. Absolutely, Your Worship. Look, I had everything under control until you led us down here. You know, it's not going to take them long to figure out what happened to us. It could be worst... It's worst. There's something alive in here! That's your imagination. Something just moves past my leg! Look! Did you see that? What? Help!",
14+
},
15+
{
16+
id: 3,
17+
content:
18+
"Oh! The garbage chute was a really wonderful idea. What an incredible smell you've discovered! Let's get out of here! Get away from there... No! wait! Will you forget it? I already tried it. It's magnetically sealed! Put that thing away! You're going to get us all killed. Absolutely, Your Worship. Look, I had everything under control until you led us down here. You know, it's not going to take them long to figure out what happened to us. It could be worst... It's worst. There's something alive in here! That's your imagination. Something just moves past my leg! Look! Did you see that? What? Help!",
19+
},
20+
{
21+
id: 4,
22+
content:
23+
"Oh! The garbage chute was a really wonderful idea. What an incredible smell you've discovered! Let's get out of here! Get away from there... No! wait! Will you forget it? I already tried it. It's magnetically sealed! Put that thing away! You're going to get us all killed. Absolutely, Your Worship. Look, I had everything under control until you led us down here. You know, it's not going to take them long to figure out what happened to us. It could be worst... It's worst. There's something alive in here! That's your imagination. Something just moves past my leg! Look! Did you see that? What? Help!",
24+
},
25+
{
26+
id: 5,
27+
content:
28+
"Oh! The garbage chute was a really wonderful idea. What an incredible smell you've discovered! Let's get out of here! Get away from there... No! wait! Will you forget it? I already tried it. It's magnetically sealed! Put that thing away! You're going to get us all killed. Absolutely, Your Worship. Look, I had everything under control until you led us down here. You know, it's not going to take them long to figure out what happened to us. It could be worst... It's worst. There's something alive in here! That's your imagination. Something just moves past my leg! Look! Did you see that? What? Help!",
29+
},
30+
{
31+
id: 6,
32+
content:
33+
"Oh! The garbage chute was a really wonderful idea. What an incredible smell you've discovered! Let's get out of here! Get away from there... No! wait! Will you forget it? I already tried it. It's magnetically sealed! Put that thing away! You're going to get us all killed. Absolutely, Your Worship. Look, I had everything under control until you led us down here. You know, it's not going to take them long to figure out what happened to us. It could be worst... It's worst. There's something alive in here! That's your imagination. Something just moves past my leg! Look! Did you see that? What? Help!",
34+
},
35+
],
36+
}
37+
}

__tests__/cli/index.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,17 @@ describe('cli', () => {
9999
})
100100
})
101101

102+
describe('seed.cjs', () => {
103+
beforeEach((done) => {
104+
child = cli(['../../__fixtures__/seed.cjs'])
105+
serverReady(PORT, done)
106+
})
107+
108+
test('should support CommonJS file', (done) => {
109+
request.get('/posts').expect(200, done)
110+
})
111+
})
112+
102113
describe('remote db', () => {
103114
beforeEach((done) => {
104115
child = cli(['https://jsonplaceholder.typicode.com/db'])

src/cli/utils/is.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ function FILE(s) {
99
}
1010

1111
function JS(s) {
12-
return !URL(s) && /\.js$/.test(s)
12+
return !URL(s) && /\.c?js$/.test(s)
1313
}
1414

1515
function URL(s) {

0 commit comments

Comments
 (0)