|
1 | 1 | import http from 'http'; |
| 2 | +import {basename} from 'path'; |
2 | 3 |
|
3 | 4 | import {assert} from 'chai'; |
4 | 5 | import fetch from 'node-fetch'; |
@@ -725,13 +726,38 @@ describe('node-static', function () { |
725 | 726 | this.server.close(); |
726 | 727 | }); |
727 | 728 |
|
728 | | - it('returns 200 with missing JSON file', async function () { |
| 729 | + it('returns 200 with multiple JSON files config', async function () { |
729 | 730 | const response = await fetch(this.getTestServer() + '/'); |
730 | 731 | assert.equal(response.status, 200, 'should respond with 200'); |
731 | 732 | assert.equal(await response.text(), 'Hi\nhello world', 'should respond with Hi\nhello world'); |
732 | 733 | }); |
733 | 734 | }); |
734 | 735 |
|
| 736 | + describe('once an http server is listening with directoryCallback', function () { |
| 737 | + before(function () { |
| 738 | + fileServer = new statik.Server(__dirname + '/../fixtures', { |
| 739 | + directoryCallback (pathname, req, res) { |
| 740 | + res.writeHead(200, { |
| 741 | + 'Content-Type': 'text/html' |
| 742 | + }); |
| 743 | + res.end(`Hi ${basename(pathname)}!`); |
| 744 | + } |
| 745 | + }); |
| 746 | + }); |
| 747 | + beforeEach(async function () { |
| 748 | + await setupStaticServer(this); |
| 749 | + }); |
| 750 | + afterEach(async function () { |
| 751 | + this.server.close(); |
| 752 | + }); |
| 753 | + |
| 754 | + it('returns 200 with directoryCallback', async function () { |
| 755 | + const response = await fetch(this.getTestServer() + '/there'); |
| 756 | + assert.equal(response.status, 200, 'should respond with 200'); |
| 757 | + assert.equal(await response.text(), 'Hi there!', 'should respond with Hi there!'); |
| 758 | + }); |
| 759 | + }); |
| 760 | + |
735 | 761 | describe('once an http server is listening with bad JSON files configuration', function () { |
736 | 762 | before(function () { |
737 | 763 | fileServer = new statik.Server(__dirname + '/../fixtures/index-with-bad-json'); |
|
0 commit comments