From 39f615c5307a59fd1f57cb33cd410d288da2066d Mon Sep 17 00:00:00 2001 From: Federico Panico Date: Wed, 22 Feb 2023 18:25:59 -0300 Subject: [PATCH] Accept .cjs (Commonjs) file for the db (#1368) --- __fixtures__/seed.cjs | 37 +++++++++++++++++++++++++++++++++++++ __tests__/cli/index.js | 11 +++++++++++ src/cli/utils/is.js | 2 +- 3 files changed, 49 insertions(+), 1 deletion(-) create mode 100644 __fixtures__/seed.cjs diff --git a/__fixtures__/seed.cjs b/__fixtures__/seed.cjs new file mode 100644 index 000000000..05622ed35 --- /dev/null +++ b/__fixtures__/seed.cjs @@ -0,0 +1,37 @@ +// Need some fake data for the gzip test to work +module.exports = function () { + return { + posts: [ + { + id: 1, + content: + "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!", + }, + { + id: 2, + content: + "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!", + }, + { + id: 3, + content: + "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!", + }, + { + id: 4, + content: + "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!", + }, + { + id: 5, + content: + "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!", + }, + { + id: 6, + content: + "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!", + }, + ], + } +} diff --git a/__tests__/cli/index.js b/__tests__/cli/index.js index 69ac1bcd4..a7f54cc7f 100644 --- a/__tests__/cli/index.js +++ b/__tests__/cli/index.js @@ -99,6 +99,17 @@ describe('cli', () => { }) }) + describe('seed.cjs', () => { + beforeEach((done) => { + child = cli(['../../__fixtures__/seed.cjs']) + serverReady(PORT, done) + }) + + test('should support CommonJS file', (done) => { + request.get('/posts').expect(200, done) + }) + }) + describe('remote db', () => { beforeEach((done) => { child = cli(['https://jsonplaceholder.typicode.com/db']) diff --git a/src/cli/utils/is.js b/src/cli/utils/is.js index 6088889de..228b4b070 100644 --- a/src/cli/utils/is.js +++ b/src/cli/utils/is.js @@ -9,7 +9,7 @@ function FILE(s) { } function JS(s) { - return !URL(s) && /\.js$/.test(s) + return !URL(s) && /\.c?js$/.test(s) } function URL(s) {