Skip to content

Commit

Permalink
test: add tests for .cjs
Browse files Browse the repository at this point in the history
  • Loading branch information
sinedied committed Jan 2, 2025
1 parent 53df4fb commit 749d6b7
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 2 deletions.
1 change: 1 addition & 0 deletions test/convert.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ describe('smoke conversion tools', () => {
"Chuck Norris writes code that optimizes itself."
],
"get_test#mocks#api#random.js": data => num.toString(),
"get_test#mocks#api#random2.cjs": data => num.toString(),
"get_test#mocks#api#test#@id__500.json_": "{\\n \\"statusCode\\": 500,\\n \\"body\\": {\\n \\"message\\": \\"Error\\"\\n }\\n}\\n",
"get_test#mocks#api#test#@id.json_": "{\\n \\"statusCode\\": 200,\\n \\"headers\\": {\\n \\"custom-header\\": \\"hello\\"\\n },\\n \\"body\\": {\\n \\"message\\": \\"id: {{params.id}}\\",\\n \\"query\\": {{JSON.stringify(query)}}\\n }\\n}\\n",
"test#mocks#api#hello.json": null,
Expand Down
2 changes: 1 addition & 1 deletion test/mocks/404.mocks.cjs → test/mocks/404.mocks.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Mock collection is also supported for 404 errors
module.exports = {
export default {
'404.txt': 'Duh! Nothing there...'
}
2 changes: 2 additions & 0 deletions test/mocks/api/get_random2.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
const num = Math.floor(Math.random() * 1000);
module.exports = data => num.toString();
6 changes: 5 additions & 1 deletion test/smoke.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,10 @@ describe('smoke server', () => {

expect(response1.body).not.toEqual(response2.body);
});

it('should support CJS mocks for backward compatibility', async () => {
await request(app).get('/api/random2').expect(200).expect('Content-Type', /json/);
});
});

describe('should use a different mock set', () => {
Expand Down Expand Up @@ -638,7 +642,7 @@ describe('smoke server', () => {
});

it('should support collection for 404 errors', async () => {
app = await createServer({...options, notFound: '404.mocks.cjs'});
app = await createServer({...options, notFound: '404.mocks.js'});
const response = await request(app).get('/api/not-found').expect(404).expect('Content-Type', /text/);

expect(response.text).toEqual('Duh! Nothing there...');
Expand Down

0 comments on commit 749d6b7

Please sign in to comment.