Skip to content

Commit

Permalink
test: updated dev server tests
Browse files Browse the repository at this point in the history
  • Loading branch information
webdeveric committed Feb 27, 2024
1 parent a1eb3e1 commit 7f6052c
Showing 1 changed file with 31 additions and 19 deletions.
50 changes: 31 additions & 19 deletions test/plugin.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1407,19 +1407,23 @@ describe('Options', () => {
it('Should serve the assets manifest JSON file', async () => {
const { compiler } = create(configs.devServer(), undefined, webpack);

const server = new WebpackDevServer(undefined, compiler);
const server = new WebpackDevServer(
{
host: 'localhost',
},
compiler,
);

await server.start();

await expect(fetch(`http://127.0.0.1:${server.options.port}/assets-manifest.json`)).resolves.toHaveProperty(
'status',
200,
);
await expect(
fetch(`http://${server.options.host}:${server.options.port}/assets-manifest.json`),
).resolves.toHaveProperty('status', 200);

await server.close();
await server.stop();
});

describe.sequential('writeToDisk', () => {
describe('writeToDisk', () => {
beforeAll(async () => {
await mkdir(getWorkspace(), { recursive: true, mode: _777 });
});
Expand All @@ -1435,20 +1439,24 @@ describe('Options', () => {
writeToDisk: true,
});

const server = new WebpackDevServer(undefined, compiler);
const server = new WebpackDevServer(
{
host: 'localhost',
},
compiler,
);

await server.start();

await expect(fetch(`http://127.0.0.1:${server.options.port}/assets-manifest.json`)).resolves.toHaveProperty(
'status',
200,
);
await expect(
fetch(`http://${server.options.host}:${server.options.port}/assets-manifest.json`),
).resolves.toHaveProperty('status', 200);

const manifestStats = await stat(manifest.getOutputPath());

expect(manifestStats.isFile()).toBeTruthy();

await server.close();
await server.stop();
});

it('Should write to compiler.outputPath if no output paths are specified', async () => {
Expand All @@ -1461,22 +1469,26 @@ describe('Options', () => {
writeToDisk: true,
});

const server = new WebpackDevServer(undefined, compiler);
const server = new WebpackDevServer(
{
host: 'localhost',
},
compiler,
);

await server.start();

await expect(fetch(`http://127.0.0.1:${server.options.port}/assets-manifest.json`)).resolves.toHaveProperty(
'status',
200,
);
await expect(
fetch(`http://${server.options.host}:${server.options.port}/assets-manifest.json`),
).resolves.toHaveProperty('status', 200);

const manifestStats = await stat(manifest.getOutputPath());

expect(manifest.getOutputPath().startsWith(compiler.outputPath)).toBeTruthy();

expect(manifestStats.isFile()).toBeTruthy();

await server.close();
await server.stop();
});

it('writeToDisk: auto', async () => {
Expand Down

0 comments on commit 7f6052c

Please sign in to comment.