Skip to content

Commit

Permalink
fix(dev-server): add and fix the test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
Tanmoy Bhowmik committed Dec 10, 2023
1 parent 3a87154 commit 376ed20
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 5 deletions.
5 changes: 5 additions & 0 deletions packages/core/integration-tests/test/html.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,11 @@ describe('html', function () {
name: 'other.html',
assets: ['other.html'],
},
{
// bar.baz.html
name: 'bar.baz.html',
assets: ['bar.baz.html'],
},
{
type: 'svg',
assets: ['icons.svg'],
Expand Down
10 changes: 10 additions & 0 deletions packages/core/integration-tests/test/integration/html/bar.baz.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<!doctype html>
<html>
<head>
<link rel="stylesheet" href="index.css" />
</head>
<body>
<h1>File name with dot</h1>
<script src="index.js"></script>
</body>
</html>
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<h1>Hello world</h1>
<p>
Linking to <a href="other.html">another page</a> and <a href="foo/index.html">another page</a>
and <a href="foo/other.html">another page</a>
and <a href="foo/other.html">another page</a> and <a href="bar.baz.html">another page</a>
</p>
<a href="#hash_link">Hash link</a>
<a href="mailto:someone@acme.com">Mailto link</a>
Expand Down
26 changes: 23 additions & 3 deletions packages/core/integration-tests/test/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -174,12 +174,27 @@ describe('server', function () {
);

assert.equal(await get('/', port), rootIndex);
assert.equal(await get('/something', port), rootIndex);
assert.equal(await get('/other', port), other);
assert.equal(await get('/foo', port), fooIndex);
assert.equal(await get('/foo?param=bar', port), fooIndex);
assert.equal(await get('/foo/', port), fooIndex);
assert.equal(await get('/foo/bar', port), fooIndex);
assert.equal(await get('/foo/?param=bar', port), fooIndex);
assert.equal(await get('/foo/index.html', port), fooIndex);
assert.equal(await get('/foo/other', port), fooOther);

try {
await get('/something', port);
} catch (err) {
assert.equal(err.statusCode, 404);
assert(err.data.includes('Page not found'));
}

try {
await get('/foo/bar', port);
} catch (err) {
assert.equal(err.statusCode, 404);
assert(err.data.includes('Page not found'));
}
});

it('should serve a default page if the single HTML bundle is not called index', async function () {
Expand Down Expand Up @@ -429,7 +444,7 @@ describe('server', function () {
let data = await get('/bar.baz', port);
assert.equal(
data,
await outputFS.readFile(path.join(distDir, 'index.html'), 'utf8'),
await outputFS.readFile(path.join(distDir, 'bar.baz.html'), 'utf8'),
);
});

Expand Down Expand Up @@ -508,6 +523,11 @@ describe('server', function () {
name: 'other.html',
assets: ['other.html'],
},
{
// bar.baz.html
name: 'bar.baz.html',
assets: ['bar.baz.html'],
},
{
type: 'svg',
assets: ['icons.svg'],
Expand Down
3 changes: 2 additions & 1 deletion packages/reporters/dev-server/src/Server.js
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,8 @@ export default class Server {
const URLpathname = req.url.split('?')[0];

// Remove forward slashes - '/some/path/' to '/some/path'
const cleanedURLpathname = URLpathname.replace(/\/+$/, '');
const cleanedURLpathname =
URLpathname === '/' ? URLpathname : URLpathname.replace(/\/+$/, '');

indexFilePath = htmlBundleFilePaths
// Sorting for multiple html file paths for url '/some/path'
Expand Down

0 comments on commit 376ed20

Please sign in to comment.