Skip to content

Commit

Permalink
Implement haku selection and use mock server for testing
Browse files Browse the repository at this point in the history
  • Loading branch information
SalamaGofore committed Mar 19, 2024
1 parent 411c406 commit 08fb526
Show file tree
Hide file tree
Showing 16 changed files with 4,631 additions and 126 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ jobs:
run: npm ci
- name: Install Playwright Browsers
run: npx playwright install --with-deps
- name: Start mockserver
run: npm run mocks &
- name: Start the app
run: npm run dev &
- name: Run Playwright tests
Expand Down
106 changes: 106 additions & 0 deletions mocks.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
// For a detailed explanation regarding each configuration property, visit:
// https://www.mocks-server.org/docs/configuration/how-to-change-settings
// https://www.mocks-server.org/docs/configuration/options

module.exports = {
// Log level. Can be one of silly, debug, verbose, info, warn or error
//log: "info",
config: {
// Allow unknown arguments
//allowUnknownArguments: false,
},
plugins: {
// Plugins to be registered
//register: [],
proxyRoutesHandler: {
},
adminApi: {
// Port number for the admin API server to be listening at
//port: 3110,
// Host for the admin API server
//host: "0.0.0.0",
https: {
// Use https protocol or not
//enabled: false,
// Path to a TLS/SSL certificate
//cert: undefined,
// Path to the certificate private key
//key: undefined,
},
},
inquirerCli: {
// Start interactive CLI or not
//enabled: true,
// Render emojis or not
//emojis: true,
},
openapi: {
collection: {
// Name for the collection created from OpenAPI definitions
//id: "openapi",
// Name of the collection to extend from
//from: undefined,
},
},
},
mock: {
routes: {
// Global delay to apply to routes
//delay: 0,
},
collections: {
// Selected collection
//selected: "base",
},
},
server: {
// Port number for the server to be listening at
port: 3104,
// Host for the server
//host: "0.0.0.0",
cors: {
// Use CORS middleware or not
//enabled: true,
// Options for the CORS middleware. Further information at https://github.com/expressjs/cors#configuration-options
//options: {"preflightContinue":false},
},
jsonBodyParser: {
// Use json body-parser middleware or not
//enabled: true,
// Options for the json body-parser middleware. Further information at https://github.com/expressjs/body-parser
//options: {},
},
urlEncodedBodyParser: {
// Use urlencoded body-parser middleware or not
//enabled: true,
// Options for the urlencoded body-parser middleware. Further information at https://github.com/expressjs/body-parser
//options: {"extended":true},
},
https: {
// Use https protocol or not
//enabled: false,
// Path to a TLS/SSL certificate
//cert: undefined,
// Path to the certificate private key
//key: undefined,
},
},
files: {
// Allows to disable files load
//enabled: true,
// Define folder from where to load collections and routes
//path: "mocks",
// Enable/disable files watcher
//watch: true,
babelRegister: {
// Load @babel/register
//enabled: false,
// Options for @babel/register
//options: {},
},
},
variantHandlers: {
// Variant Handlers to be registered
//register: [],
},
};
21 changes: 21 additions & 0 deletions mocks/collections.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
[
{
"id": "base",
"routes": ["add-headers:enabled", "get-users:success", "get-user:success", "get-haut:success"]
},
{
"id": "no-headers",
"from": "base",
"routes": ["add-headers:disabled"]
},
{
"id": "all-users",
"from": "base",
"routes": ["get-users:all", "get-user:id-3"]
},
{
"id": "user-real",
"from": "no-headers",
"routes": ["get-user:real"]
}
]
29 changes: 29 additions & 0 deletions mocks/routes/common.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// Use this file only as a guide for first steps using middleware variants. You can delete it when you have understood the concepts.
// For a detailed explanation about using middlewares, visit:
// https://mocks-server.org/docs/usage/variants/middlewares

module.exports = [
{
id: "add-headers", //route id
url: "*", // url in express format
method: ["GET", "POST", "PUT", "PATCH"], // HTTP methods
variants: [
{
id: "enabled", // variant id
type: "middleware", // variant handler id
options: {
// Express middleware to execute
middleware: (_req, res, next, core) => {
res.set("x-mocks-server-example", "some-value");
core.logger.info("Custom header added by route variant middleware");
next();
},
},
},
{
id: "disabled", // variant id
disabled: true,
},
],
},
];
Loading

0 comments on commit 08fb526

Please sign in to comment.