-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
61e6878
commit 6390507
Showing
8 changed files
with
159 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
// For a detailed explanation regarding each configuration property, visit: | ||
// https://jestjs.io/docs/en/configuration.html | ||
|
||
module.exports = { | ||
// Automatically clear mock calls and instances between every test | ||
clearMocks: true, | ||
|
||
// A set of global variables that need to be available in all test environments | ||
globals: { | ||
__PATH_PREFIX__: ``, | ||
}, | ||
|
||
// An array of directory names to be searched recursively up from the requiring module's location | ||
moduleDirectories: [`node_modules`], | ||
|
||
modulePathIgnorePatterns: [`<rootDir>/test-site/`], | ||
// The test environment that will be used for testing | ||
testEnvironment: `node`, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 18 additions & 0 deletions
18
packages/gatsby-plugin-fastify/src/__tests__/__snapshots__/serve.js.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`Test Gatsby Server Should work 1`] = ` | ||
"<!DOCTYPE html> | ||
<html lang=\\"en\\"> | ||
<head> | ||
<meta charset=\\"utf-8\\"> | ||
<meta name=\\"viewport\\" content=\\"width=device-width, initial-scale=1.0\\"> | ||
<title>Gatsby Plugin Fastify</title> | ||
</head> | ||
<body> | ||
<h1>Hello World</h1> | ||
</body> | ||
</html>" | ||
`; |
14 changes: 14 additions & 0 deletions
14
packages/gatsby-plugin-fastify/src/__tests__/public/index.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
|
||
<head> | ||
<meta charset="utf-8"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
<title>Gatsby Plugin Fastify</title> | ||
</head> | ||
|
||
<body> | ||
<h1>Hello World</h1> | ||
</body> | ||
|
||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
const { gatsbyServer } = require("../serve"); | ||
const { ConfigKeyEnum, setConfig } = require("../utils/config"); | ||
|
||
jest.mock("../utils/constants", () => ({ | ||
PATH_TO_PUBLIC: __dirname + "/public/", | ||
})); | ||
|
||
function createCliConfig({ host, port, verbose, open }) { | ||
return { | ||
host, | ||
h: host, | ||
port, | ||
p: port, | ||
verbose, | ||
v: verbose, | ||
open, | ||
o: open, | ||
}; | ||
} | ||
|
||
describe(`Test Gatsby Server`, () => { | ||
beforeAll(() => { | ||
setConfig( | ||
ConfigKeyEnum.CLI, | ||
createCliConfig({ | ||
port: 3000, | ||
host: "127.0.0.1", | ||
verbose: false, | ||
open: false, | ||
}), | ||
); | ||
|
||
setConfig(ConfigKeyEnum.SERVER, { | ||
clientSideRoutes: [], | ||
redirects: [], | ||
prefix: "", | ||
functions: [], | ||
}); | ||
}); | ||
|
||
it(`Should 404`, async () => { | ||
setConfig(ConfigKeyEnum.SERVER, { | ||
clientSideRoutes: [], | ||
redirects: [], | ||
prefix: "", | ||
functions: [], | ||
}); | ||
|
||
const fastify = await gatsbyServer(); | ||
|
||
const response = await fastify.inject({ | ||
url: "/badRoute", | ||
method: "GET", | ||
}); | ||
|
||
await fastify.close(); | ||
|
||
expect(response.statusCode).toEqual(404); | ||
}); | ||
|
||
it(`Should work`, async () => { | ||
const fastify = await gatsbyServer(); | ||
|
||
const response = await fastify.inject({ | ||
url: "/", | ||
method: "GET", | ||
}); | ||
|
||
await fastify.close(); | ||
|
||
expect(response.statusCode).toEqual(200); | ||
expect(response.payload).toMatchSnapshot(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters