Skip to content

Commit 087bf52

Browse files
committed
chore(test): fix tests
Fix `generate` test. Properly name `generate` test. Properly handle async operations. Change `dev` and `generate` tests to use snapshots. Add `dev` snapshot.
1 parent 279e865 commit 087bf52

File tree

6 files changed

+49
-18
lines changed

6 files changed

+49
-18
lines changed

test/__snapshots__/dev.test.js.snap

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// Jest Snapshot v1, https://goo.gl/fbAQLP
2+
3+
exports[`module dev mode admin 1`] = `
4+
"<!DOCTYPE html>
5+
<html>
6+
<head>
7+
<meta charset=\\"utf-8\\" />
8+
<meta name=\\"viewport\\" content=\\"width=device-width, initial-scale=1.0\\" />
9+
<link href=\\"/admin/config.yml\\" type=\\"text/yaml\\" rel=\\"cms-config-url\\">
10+
<title>Content Manager</title>
11+
</head>
12+
<body>
13+
<script type=\\"text/javascript\\" src=\\"/admin/bundle.d1e28a1f3d3e1d943036.js\\"></script></body>
14+
</html>
15+
"
16+
`;

test/config.test.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,14 @@ jest.mock("../src/utils/yaml");
33

44
import { get, commonBefore, commonAfter } from "./nuxt";
55

6-
describe("config", () => {
7-
beforeAll(commonBefore());
6+
describe("config", async () => {
7+
beforeAll(async () => {
8+
await commonBefore()();
9+
});
810

9-
afterAll(commonAfter);
11+
afterAll(async () => {
12+
await commonAfter();
13+
});
1014

1115
test("netlify-cms.yml", async () => {
1216
const config = await get("/admin/config.yml");

test/dev.test.js

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
11
import { get, commonBefore, commonAfter } from "./nuxt";
22

3-
describe("module dev mode", () => {
4-
beforeAll(commonBefore({ dev: true }));
3+
describe("module dev mode", async () => {
4+
beforeAll(async () => {
5+
await commonBefore({ dev: true })();
6+
});
57

6-
afterAll(commonAfter);
8+
afterAll(async () => {
9+
await commonAfter();
10+
});
711

812
test("render", async () => {
913
const html = await get("/");
@@ -12,6 +16,6 @@ describe("module dev mode", () => {
1216

1317
test("admin", async () => {
1418
const html = await get("/admin/");
15-
expect(html).toMatch(/.*<script[\s\S]*?>[\s\S]*?<\/script><\/body>/);
19+
expect(html).toMatchSnapshot();
1620
});
1721
});

test/generate.test.js

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
11
import { get, generate, generateAfter } from "./nuxt";
22

3-
describe("module dev mode", () => {
4-
beforeAll(generate());
3+
describe("module generate mode", async () => {
4+
beforeAll(async () => {
5+
await generate()();
6+
});
57

6-
afterAll(generateAfter);
8+
afterAll(async () => {
9+
await generateAfter();
10+
});
711

812
test("admin", async () => {
913
const html = await get("/admin/");
10-
expect(html).toMatch(/.*<script[\s\S]*?>[\s\S]*?<\/script><\/body>/);
14+
expect(html).toMatchSnapshot();
1115
});
1216
});

test/module.test.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
11
import { get, commonBefore, commonAfter } from "./nuxt";
22

3-
describe("module", () => {
4-
beforeAll(commonBefore());
3+
describe("module", async () => {
4+
beforeAll(async () => {
5+
await commonBefore()();
6+
});
57

6-
afterAll(commonAfter);
8+
afterAll(async () => {
9+
await commonAfter();
10+
});
711

812
test("render", async () => {
913
const html = await get("/");

test/nuxt.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import { join } from "path";
2-
31
import { Nuxt, Builder, Generator } from "nuxt";
42
import request from "request-promise-native";
53
import Koa from "koa";
@@ -15,12 +13,13 @@ const url = path => `http://localhost:${process.env.PORT}${path}`;
1513
const get = path => request(url(path));
1614

1715
let nuxt;
16+
let generator;
1817
let server;
1918

2019
const serve = () => {
2120
const app = new Koa();
2221

23-
app.use(serveStatic(join(nuxt.options.buildDir, "dist")));
22+
app.use(serveStatic(generator.distPath));
2423
server = app.listen(process.env.PORT);
2524
};
2625

@@ -54,7 +53,7 @@ const generate = (config = {}) => async () => {
5453
// Build a fresh nuxt
5554
nuxt = new Nuxt(mergedConfig);
5655
const builder = new Builder(nuxt);
57-
const generator = new Generator(nuxt, builder);
56+
generator = new Generator(nuxt, builder);
5857
await generator.generate();
5958
serve();
6059
};

0 commit comments

Comments
 (0)