@digigov/cli-app 1.2.3 → 2.0.0-07ee8440
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.rush/temp/shrinkwrap-deps.json +17 -410
- package/common.js +4 -0
- package/index.js +19 -84
- package/{next.common.js → next.common.cjs} +6 -6
- package/next.config.cjs +1 -0
- package/nextrc.cjs +5 -0
- package/package.json +27 -13
- package/postcss.config.cjs +1 -0
- package/postcssrc.cjs +5 -0
- package/subcommands/build.js +15 -0
- package/subcommands/dev.js +28 -0
- package/subcommands/export.js +16 -0
- package/subcommands/start.js +22 -0
- package/subcommands/test.js +34 -0
- package/tailwind.config.cjs +1 -0
- package/tailwindrc.cjs +5 -0
- package/tsconfig.json +4 -0
- package/utils/proxy-server.js +47 -0
- package/utils/test-init.js +177 -0
- package/lib/test/init.js +0 -131
- package/next.config.js +0 -1
- package/nextrc.js +0 -5
- package/postcss.config.js +0 -1
- package/postcssrc.js +0 -5
- package/proxy-server.js +0 -55
- package/tailwind.config.js +0 -1
- package/tailwindrc.js +0 -5
- /package/{postcss.common.js → postcss.common.cjs} +0 -0
- /package/{tailwind.common.js → tailwind.common.cjs} +0 -0
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
const path = require(
|
|
2
|
-
const lib = require(
|
|
3
|
-
let aliases = lib.aliases(
|
|
4
|
-
const withImages = require(
|
|
5
|
-
const { makeBabelConfig } = require(
|
|
1
|
+
const path = require("path");
|
|
2
|
+
const lib = require("@digigov/cli/lib");
|
|
3
|
+
let aliases = lib.aliases(true);
|
|
4
|
+
const withImages = require("next-images");
|
|
5
|
+
const { makeBabelConfig } = require("@digigov/cli-build/babel.common.cjs");
|
|
6
6
|
|
|
7
7
|
function makeNextConfig(dir) {
|
|
8
8
|
const project = lib.resolveProject(dir);
|
|
@@ -13,7 +13,7 @@ function makeNextConfig(dir) {
|
|
|
13
13
|
...digigov.aliases,
|
|
14
14
|
};
|
|
15
15
|
}
|
|
16
|
-
console.log(`Creating aliases for ${Object.keys(aliases).join(
|
|
16
|
+
console.log(`Creating aliases for ${Object.keys(aliases).join(", ")}`);
|
|
17
17
|
const nextConfig = withImages({
|
|
18
18
|
poweredByHeader: false,
|
|
19
19
|
trailingSlash: true,
|
package/next.config.cjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
module.exports = require("./next.common.cjs").config;
|
package/nextrc.cjs
ADDED
package/package.json
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@digigov/cli-app",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.0-07ee8440",
|
|
4
4
|
"description": "@digigov developer cli tool",
|
|
5
|
-
"main": "index.js",
|
|
5
|
+
"main": "./index.js",
|
|
6
|
+
"type": "module",
|
|
6
7
|
"author": "GRNET Developers <devs@lists.grnet.gr>",
|
|
7
8
|
"license": "BSD-2-Clause",
|
|
8
9
|
"dependencies": {
|
|
@@ -10,27 +11,40 @@
|
|
|
10
11
|
"express": "4.17.1",
|
|
11
12
|
"http-proxy-middleware": "1.0.3",
|
|
12
13
|
"next-images": "1.3.0",
|
|
13
|
-
"@digigov/cli-build": "
|
|
14
|
+
"@digigov/cli-build": "2.0.0-07ee8440",
|
|
14
15
|
"url-loader": "4.1.1",
|
|
15
16
|
"next": "13.1.1",
|
|
16
|
-
"
|
|
17
|
-
"
|
|
18
|
-
"
|
|
19
|
-
"glob": "7.1.6"
|
|
17
|
+
"commander": "12.1.0",
|
|
18
|
+
"globby": "11.0.0",
|
|
19
|
+
"publint": "0.1.8"
|
|
20
20
|
},
|
|
21
21
|
"peerDependencies": {
|
|
22
22
|
"rimraf": "3.0.2",
|
|
23
|
-
"
|
|
24
|
-
"
|
|
25
|
-
"typescript": "5.3.2",
|
|
23
|
+
"@digigov/cli": "2.0.0-07ee8440",
|
|
24
|
+
"typescript": "5.6.2",
|
|
26
25
|
"@types/node": "18.19.0",
|
|
27
26
|
"@types/react": "18.3.3",
|
|
28
27
|
"autoprefixer": "10.4.16",
|
|
29
28
|
"postcss": "8.4.4",
|
|
30
|
-
"@digigov/css": "
|
|
31
|
-
"tailwindcss": "3.
|
|
29
|
+
"@digigov/css": "2.0.0-07ee8440",
|
|
30
|
+
"tailwindcss": "3.4.13"
|
|
31
|
+
},
|
|
32
|
+
"exports": {
|
|
33
|
+
".": "./index.js",
|
|
34
|
+
"./next.common": "./next.common.cjs",
|
|
35
|
+
"./next.config": "./next.config.cjs",
|
|
36
|
+
"./nextrc": "./nextrc.cjs",
|
|
37
|
+
"./postcss.config": "./postcss.config.cjs",
|
|
38
|
+
"./postcss.common": "./postcss.common.cjs",
|
|
39
|
+
"./postcssrc": "./postcssrc.cjs",
|
|
40
|
+
"./tailwind.config": "./tailwind.config.cjs",
|
|
41
|
+
"./tailwind.common": "./tailwind.common.cjs",
|
|
42
|
+
"./tailwindrc": "./tailwindrc.cjs"
|
|
43
|
+
},
|
|
44
|
+
"devDependencies": {
|
|
45
|
+
"typescript": "5.6.2"
|
|
32
46
|
},
|
|
33
47
|
"scripts": {
|
|
34
48
|
"publint": "publint"
|
|
35
49
|
}
|
|
36
|
-
}
|
|
50
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
module.exports = require("./postcss.common.cjs").config;
|
package/postcssrc.cjs
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { DigigovCommand } from "@digigov/cli/lib";
|
|
2
|
+
import { EXEC_CONFIG } from "../common.js";
|
|
3
|
+
|
|
4
|
+
const buildCommand = new DigigovCommand("build");
|
|
5
|
+
|
|
6
|
+
buildCommand
|
|
7
|
+
.argument("[...args]", "Arguments to pass to the `next build` command")
|
|
8
|
+
.helpOption(false)
|
|
9
|
+
.allowUnknownOption()
|
|
10
|
+
.action(async (args = [], _, ctx) => {
|
|
11
|
+
await ctx.exec("rimraf", ["out"]);
|
|
12
|
+
await ctx.exec("next", ["build", ...args], EXEC_CONFIG);
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
export default buildCommand;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { DigigovCommand, resolveProject, logger } from "@digigov/cli/lib";
|
|
2
|
+
import { EXEC_CONFIG } from "../common.js";
|
|
3
|
+
|
|
4
|
+
import path from "path";
|
|
5
|
+
import { fileURLToPath } from "url";
|
|
6
|
+
|
|
7
|
+
const { digigov } = resolveProject();
|
|
8
|
+
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
|
9
|
+
|
|
10
|
+
const devCommand = new DigigovCommand("dev");
|
|
11
|
+
|
|
12
|
+
devCommand
|
|
13
|
+
.argument("[...args]", "Arguments to pass to the `next dev` command")
|
|
14
|
+
.helpOption(false)
|
|
15
|
+
.allowUnknownOption()
|
|
16
|
+
.action(async (args = [], _, ctx) => {
|
|
17
|
+
logger.info("Starting development server...");
|
|
18
|
+
if (digigov && digigov.proxy) {
|
|
19
|
+
await ctx.exec(
|
|
20
|
+
"node",
|
|
21
|
+
[path.resolve(__dirname, "../utils/proxy-server.js")],
|
|
22
|
+
EXEC_CONFIG,
|
|
23
|
+
);
|
|
24
|
+
}
|
|
25
|
+
await ctx.exec("next", ["dev", ...(args ?? [])], EXEC_CONFIG);
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
export default devCommand;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { DigigovCommand } from "@digigov/cli/lib";
|
|
2
|
+
import { EXEC_CONFIG } from "../common.js";
|
|
3
|
+
|
|
4
|
+
const exportCommand = new DigigovCommand("export");
|
|
5
|
+
|
|
6
|
+
exportCommand
|
|
7
|
+
.argument("[...args]", "Arguments to pass to the `next export` command")
|
|
8
|
+
.helpOption(false)
|
|
9
|
+
.allowUnknownOption()
|
|
10
|
+
.action(async (args = [], _, ctx) => {
|
|
11
|
+
await ctx.exec("rimraf", ["out"]);
|
|
12
|
+
await ctx.exec("next", ["build"]);
|
|
13
|
+
await ctx.exec("next", ["export", ...args], EXEC_CONFIG);
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
export default exportCommand;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import fs from "fs";
|
|
2
|
+
|
|
3
|
+
import { DigigovCommand, resolveProject } from "@digigov/cli/lib";
|
|
4
|
+
import { EXEC_CONFIG } from "../common.js";
|
|
5
|
+
import path from "path";
|
|
6
|
+
|
|
7
|
+
const startCommand = new DigigovCommand("start");
|
|
8
|
+
|
|
9
|
+
const project = resolveProject();
|
|
10
|
+
|
|
11
|
+
startCommand
|
|
12
|
+
.argument("[...args]", "Arguments to pass to the `next start` command")
|
|
13
|
+
.helpOption(false)
|
|
14
|
+
.allowUnknownOption()
|
|
15
|
+
.action(async (args = [], _, ctx) => {
|
|
16
|
+
if (!fs.existsSync(path.join(project.root, ".next"))) {
|
|
17
|
+
await ctx.exec("next", ["build"]);
|
|
18
|
+
}
|
|
19
|
+
await ctx.exec("next", ["start", ...args], EXEC_CONFIG);
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
export default startCommand;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { Option } from "commander";
|
|
2
|
+
|
|
3
|
+
import { logger, DigigovCommand } from "@digigov/cli/lib";
|
|
4
|
+
import generatePagesTestFile from "../utils/test-init.js";
|
|
5
|
+
|
|
6
|
+
const testCommand = new DigigovCommand("test");
|
|
7
|
+
|
|
8
|
+
testCommand
|
|
9
|
+
.description("Initialize project with specified parameters")
|
|
10
|
+
.option(
|
|
11
|
+
"-b, --base-url",
|
|
12
|
+
"The base url of the running project",
|
|
13
|
+
"http://localhost:3000",
|
|
14
|
+
)
|
|
15
|
+
.option(
|
|
16
|
+
"-p, --pages-path",
|
|
17
|
+
"The directory where the pages are located relative to the project folder",
|
|
18
|
+
"pages",
|
|
19
|
+
)
|
|
20
|
+
.addOption(
|
|
21
|
+
new Option("-s, --screen-sizes", "The screen sizes for viewport")
|
|
22
|
+
.choices(["xs", "lg"])
|
|
23
|
+
.default("lg"),
|
|
24
|
+
)
|
|
25
|
+
.action(async (options) => {
|
|
26
|
+
const { baseUrl, pagesPath, screenSizes } = options;
|
|
27
|
+
logger.log(
|
|
28
|
+
`Generating test files for pagesPath "${pagesPath}" with baseUrl "${baseUrl}" for screen sizes "${screenSizes}"`,
|
|
29
|
+
);
|
|
30
|
+
const projectFolder = process.cwd();
|
|
31
|
+
generatePagesTestFile(projectFolder, pagesPath, baseUrl, screenSizes);
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
export default testCommand;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
module.exports = require("./tailwind.common.cjs").config;
|
package/tailwindrc.cjs
ADDED
package/tsconfig.json
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import express from "express";
|
|
2
|
+
import next from "next";
|
|
3
|
+
import path from "path";
|
|
4
|
+
import { createRequire } from "module";
|
|
5
|
+
|
|
6
|
+
import { resolveProject } from "@digigov/cli/lib";
|
|
7
|
+
|
|
8
|
+
const port = parseInt(process.env["PORT"] ?? "3000", 10);
|
|
9
|
+
const isDev = process.env.NODE_ENV !== "production";
|
|
10
|
+
|
|
11
|
+
const project = resolveProject();
|
|
12
|
+
const devProxy = project.digigov.proxy;
|
|
13
|
+
|
|
14
|
+
const require = createRequire(import.meta.url);
|
|
15
|
+
const conf = require(path.join(project.root, "next.config.js"));
|
|
16
|
+
|
|
17
|
+
const app = next.default({
|
|
18
|
+
dir: project.root, // base directory where everything is, could move to src later
|
|
19
|
+
dev: isDev,
|
|
20
|
+
conf,
|
|
21
|
+
});
|
|
22
|
+
const handle = app.getRequestHandler();
|
|
23
|
+
|
|
24
|
+
app
|
|
25
|
+
.prepare()
|
|
26
|
+
.then(() => {
|
|
27
|
+
const server = express();
|
|
28
|
+
|
|
29
|
+
// Set up the proxy.
|
|
30
|
+
if (isDev && devProxy) {
|
|
31
|
+
const { createProxyMiddleware } = require("http-proxy-middleware");
|
|
32
|
+
Object.keys(devProxy).forEach(function (context) {
|
|
33
|
+
server.use(createProxyMiddleware(context, devProxy[context]));
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
// Default catch-all handler to allow Next.js to handle all other routes
|
|
38
|
+
server.all("*", (req, res) => handle(req, res));
|
|
39
|
+
|
|
40
|
+
server.listen(port, () => {
|
|
41
|
+
console.log(`> Ready on port ${port}`);
|
|
42
|
+
});
|
|
43
|
+
})
|
|
44
|
+
.catch((err) => {
|
|
45
|
+
console.log("An error occurred, unable to start the server");
|
|
46
|
+
console.log(err);
|
|
47
|
+
});
|
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
import fs from "fs";
|
|
2
|
+
import path from "path";
|
|
3
|
+
import glob from "globby";
|
|
4
|
+
|
|
5
|
+
const FILE_EXTENSIONS = ["js", "jsx", "ts", "tsx"];
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* @typedef {"xs" | "lg"} ScreenSize
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
const SCREEN_SIZES = {
|
|
12
|
+
xs: { width: 375, height: 667, deviceScaleFactor: 1 },
|
|
13
|
+
lg: { width: 1280, height: 720, deviceScaleFactor: 2 },
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Append test file with the test for the given file
|
|
18
|
+
*
|
|
19
|
+
* @param {string} fileRelativePath - The relative path of the file
|
|
20
|
+
* @param {string} testFile - The test file
|
|
21
|
+
* @param {ScreenSize[]} screenSizes - The screen sizes
|
|
22
|
+
*/
|
|
23
|
+
function appendTestFile(fileRelativePath, testFile, screenSizes) {
|
|
24
|
+
if (screenSizes.length > 0) {
|
|
25
|
+
screenSizes.forEach((screenSize) => {
|
|
26
|
+
testFile += `\ntest('${fileRelativePath.replace("index", "")} screen-${screenSize}', async () => {
|
|
27
|
+
await page${screenSize.toUpperCase()}.goto(\`\${baseUrl}${fileRelativePath.replace("index", "")}\`);
|
|
28
|
+
await delay(SCREENSHOT_DELAY);
|
|
29
|
+
await page${screenSize.toUpperCase()}.waitForLoadState('domcontentloaded');
|
|
30
|
+
const screenshot = await page${screenSize.toUpperCase()}.screenshot({ fullPage: true });
|
|
31
|
+
expect(screenshot).toMatchSnapshot();
|
|
32
|
+
});\n`;
|
|
33
|
+
});
|
|
34
|
+
} else {
|
|
35
|
+
testFile += `\ntest('${fileRelativePath.replace("index", "")}', async () => {
|
|
36
|
+
await page.goto(\`\${baseUrl}${fileRelativePath.replace("index", "")}\`);
|
|
37
|
+
await delay(SCREENSHOT_DELAY);
|
|
38
|
+
await page.waitForLoadState('domcontentloaded');
|
|
39
|
+
const screenshot = await page.screenshot({ fullPage: true });
|
|
40
|
+
expect(screenshot).toMatchSnapshot();
|
|
41
|
+
});\n`;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
return testFile;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Generate browser contexts
|
|
49
|
+
*
|
|
50
|
+
* @param {ScreenSize[]} screenSizes - The screen sizes
|
|
51
|
+
*/
|
|
52
|
+
function generateBrowserContexts(screenSizes) {
|
|
53
|
+
let viewportSizes = "";
|
|
54
|
+
if (screenSizes.length > 0) {
|
|
55
|
+
screenSizes.forEach((screenSize) => {
|
|
56
|
+
viewportSizes += `\n// Create a context with "${screenSize}" screen size
|
|
57
|
+
const context${screenSize.toUpperCase()} = await browser.newContext({
|
|
58
|
+
viewport: { width: ${SCREEN_SIZES[screenSize].width}, height: ${SCREEN_SIZES[screenSize].height} },
|
|
59
|
+
deviceScaleFactor: ${SCREEN_SIZES[screenSize].deviceScaleFactor},
|
|
60
|
+
});\n`;
|
|
61
|
+
});
|
|
62
|
+
} else {
|
|
63
|
+
viewportSizes += `// Create a context with default screen size
|
|
64
|
+
const context = await browser.newContext();\n`;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
return viewportSizes;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* Initialize pages
|
|
72
|
+
*
|
|
73
|
+
* @param {ScreenSize[]} screenSizes - The screen sizes
|
|
74
|
+
*/
|
|
75
|
+
function initializePages(screenSizes) {
|
|
76
|
+
let initializePages = "";
|
|
77
|
+
if (screenSizes.length > 0) {
|
|
78
|
+
screenSizes.forEach((screenSize) => {
|
|
79
|
+
initializePages += `let page${screenSize.toUpperCase()};\n`;
|
|
80
|
+
});
|
|
81
|
+
} else {
|
|
82
|
+
initializePages += "let page;\n";
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
return initializePages;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* Generate new pages
|
|
90
|
+
*
|
|
91
|
+
* @param {ScreenSize[]} screenSizes - The screen sizes
|
|
92
|
+
*/
|
|
93
|
+
function generateNewPages(screenSizes) {
|
|
94
|
+
let newPages = "";
|
|
95
|
+
if (screenSizes.length > 0) {
|
|
96
|
+
screenSizes.forEach((screenSize) => {
|
|
97
|
+
newPages += `page${screenSize.toUpperCase()} = await context${screenSize.toUpperCase()}.newPage();\n`;
|
|
98
|
+
});
|
|
99
|
+
} else {
|
|
100
|
+
newPages += "page = await context.newPage();\n";
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
return newPages;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* Generate pages test file
|
|
108
|
+
*
|
|
109
|
+
* @param {string} projectFolder - The project folder
|
|
110
|
+
* @param {string} [pagesPath="pages"] - The pages path
|
|
111
|
+
* @param {string} [baseUrl="http://localhost:3000"] - The base URL
|
|
112
|
+
* @param {string} [testFileName="index.spec.ts"] - The test file name
|
|
113
|
+
* @param {ScreenSize[]} [screenSizes=[]] - The screen sizes
|
|
114
|
+
*/
|
|
115
|
+
function generatePagesTestFile(
|
|
116
|
+
projectFolder,
|
|
117
|
+
pagesPath = "pages",
|
|
118
|
+
baseUrl = "http://localhost:3000",
|
|
119
|
+
testFileName = "index.spec.ts",
|
|
120
|
+
screenSizes = [],
|
|
121
|
+
) {
|
|
122
|
+
let pagesFullPath = "";
|
|
123
|
+
if (fs.existsSync(path.join(projectFolder, pagesPath))) {
|
|
124
|
+
pagesFullPath = path.join(projectFolder, pagesPath);
|
|
125
|
+
} else if (fs.existsSync(path.join(projectFolder, "src", pagesPath))) {
|
|
126
|
+
pagesFullPath = path.join(projectFolder, `src/${pagesPath}`);
|
|
127
|
+
}
|
|
128
|
+
let testFile = `import { test, expect } from '@playwright/test';
|
|
129
|
+
import { chromium } from 'playwright';
|
|
130
|
+
|
|
131
|
+
const baseUrl = '${baseUrl}';
|
|
132
|
+
const SCREENSHOT_DELAY = 2000;
|
|
133
|
+
|
|
134
|
+
test.describe('/pages', () => {
|
|
135
|
+
let browser;
|
|
136
|
+
${initializePages(screenSizes)}
|
|
137
|
+
|
|
138
|
+
const delay = ms => new Promise(resolve => setTimeout(resolve, ms));
|
|
139
|
+
|
|
140
|
+
test.beforeAll(async () => {
|
|
141
|
+
// Wait until yarn start is loaded
|
|
142
|
+
test.setTimeout(60000);
|
|
143
|
+
await delay(30000);
|
|
144
|
+
browser = await chromium.launch();
|
|
145
|
+
${generateBrowserContexts(screenSizes)}
|
|
146
|
+
${generateNewPages(screenSizes)}
|
|
147
|
+
});
|
|
148
|
+
|
|
149
|
+
test.afterAll(async () => {
|
|
150
|
+
await browser.close();
|
|
151
|
+
});
|
|
152
|
+
`;
|
|
153
|
+
|
|
154
|
+
const pagesPathRegex = new RegExp(
|
|
155
|
+
`.*${pagesFullPath.replace("/", "\\/")}(.*)`,
|
|
156
|
+
);
|
|
157
|
+
glob
|
|
158
|
+
.sync(`${pagesFullPath}/**/*.@(${FILE_EXTENSIONS.join("|")})`)
|
|
159
|
+
.forEach((fileFullPath) => {
|
|
160
|
+
const fileRelativePath = fileFullPath.replace(pagesPathRegex, "$1");
|
|
161
|
+
const pageFileName = fileRelativePath.substring(
|
|
162
|
+
fileRelativePath.lastIndexOf("/") + 1,
|
|
163
|
+
);
|
|
164
|
+
// Check of the file starts with letter or digit
|
|
165
|
+
if (/^[a-zA-Z0-9]/.test(pageFileName)) {
|
|
166
|
+
testFile = appendTestFile(
|
|
167
|
+
fileRelativePath.replace(/\.[^/.]+$/, ""),
|
|
168
|
+
testFile,
|
|
169
|
+
screenSizes,
|
|
170
|
+
);
|
|
171
|
+
}
|
|
172
|
+
});
|
|
173
|
+
testFile += "\n});";
|
|
174
|
+
fs.writeFileSync(path.join(projectFolder, testFileName), testFile);
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
export default generatePagesTestFile;
|
package/lib/test/init.js
DELETED
|
@@ -1,131 +0,0 @@
|
|
|
1
|
-
const fs = require('fs');
|
|
2
|
-
const path = require('path');
|
|
3
|
-
const glob = require('glob');
|
|
4
|
-
|
|
5
|
-
const FILE_EXTENSIONS = ['js', 'jsx', 'ts', 'tsx'];
|
|
6
|
-
|
|
7
|
-
const SCREEN_SIZES = {
|
|
8
|
-
'xs': { width: 375, height: 667, deviceScaleFactor: 1 },
|
|
9
|
-
'lg': { width: 1280, height: 720, deviceScaleFactor: 2 }
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
const appendTestFile = (fileRelativePath, testFile, screenSizes) => {
|
|
13
|
-
if (screenSizes.length > 0) {
|
|
14
|
-
screenSizes.forEach((screenSize) => {
|
|
15
|
-
testFile += `\ntest('${fileRelativePath.replace('index', '')} screen-${screenSize}', async () => {
|
|
16
|
-
await page${screenSize.toUpperCase()}.goto(\`\${baseUrl}${fileRelativePath.replace('index', '')}\`);
|
|
17
|
-
await delay(SCREENSHOT_DELAY);
|
|
18
|
-
await page${screenSize.toUpperCase()}.waitForLoadState('domcontentloaded');
|
|
19
|
-
const screenshot = await page${screenSize.toUpperCase()}.screenshot({ fullPage: true });
|
|
20
|
-
expect(screenshot).toMatchSnapshot();
|
|
21
|
-
});\n`;
|
|
22
|
-
});
|
|
23
|
-
}
|
|
24
|
-
else {
|
|
25
|
-
testFile += `\ntest('${fileRelativePath.replace('index', '')}', async () => {
|
|
26
|
-
await page.goto(\`\${baseUrl}${fileRelativePath.replace('index', '')}\`);
|
|
27
|
-
await delay(SCREENSHOT_DELAY);
|
|
28
|
-
await page.waitForLoadState('domcontentloaded');
|
|
29
|
-
const screenshot = await page.screenshot({ fullPage: true });
|
|
30
|
-
expect(screenshot).toMatchSnapshot();
|
|
31
|
-
});\n`;
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
return testFile;
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
const generateBrowserContexts = (screenSizes) => {
|
|
38
|
-
let viewportSizes = '';
|
|
39
|
-
if (screenSizes.length > 0) {
|
|
40
|
-
screenSizes.forEach((screenSize) => {
|
|
41
|
-
viewportSizes += `\n// Create a context with "${screenSize}" screen size
|
|
42
|
-
const context${screenSize.toUpperCase()} = await browser.newContext({
|
|
43
|
-
viewport: { width: ${SCREEN_SIZES[screenSize].width}, height: ${SCREEN_SIZES[screenSize].height} },
|
|
44
|
-
deviceScaleFactor: ${SCREEN_SIZES[screenSize].deviceScaleFactor},
|
|
45
|
-
});\n`;
|
|
46
|
-
});
|
|
47
|
-
}
|
|
48
|
-
else {
|
|
49
|
-
viewportSizes += `// Create a context with default screen size
|
|
50
|
-
const context = await browser.newContext();\n`;
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
return viewportSizes;
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
const initializePages = (screenSizes) => {
|
|
57
|
-
let initializePages = '';
|
|
58
|
-
if (screenSizes.length > 0) {
|
|
59
|
-
screenSizes.forEach((screenSize) => {
|
|
60
|
-
initializePages += `let page${screenSize.toUpperCase()};\n`;
|
|
61
|
-
});
|
|
62
|
-
}
|
|
63
|
-
else {
|
|
64
|
-
initializePages += 'let page;\n';
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
return initializePages;
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
const generateNewPages = (screenSizes) => {
|
|
71
|
-
let newPages = '';
|
|
72
|
-
if (screenSizes.length > 0) {
|
|
73
|
-
screenSizes.forEach((screenSize) => {
|
|
74
|
-
newPages += `page${screenSize.toUpperCase()} = await context${screenSize.toUpperCase()}.newPage();\n`;
|
|
75
|
-
});
|
|
76
|
-
}
|
|
77
|
-
else {
|
|
78
|
-
newPages += 'page = await context.newPage();\n';
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
return newPages;
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
const generatePagesTestFile = (projectFolder, pagesPath = 'pages', baseUrl = 'http://localhost:3000', testFileName = 'index.spec.ts', screenSizes = []) => {
|
|
85
|
-
let pagesFullPath = '';
|
|
86
|
-
if (fs.existsSync(path.join(projectFolder, pagesPath))) {
|
|
87
|
-
pagesFullPath = path.join(projectFolder, pagesPath);
|
|
88
|
-
}
|
|
89
|
-
else if (fs.existsSync(path.join(projectFolder, 'src', pagesPath))) {
|
|
90
|
-
pagesFullPath = path.join(projectFolder, `src/${pagesPath}`);
|
|
91
|
-
}
|
|
92
|
-
let testFile = `import { test, expect } from '@playwright/test';
|
|
93
|
-
import { chromium } from 'playwright';
|
|
94
|
-
|
|
95
|
-
const baseUrl = '${baseUrl}';
|
|
96
|
-
const SCREENSHOT_DELAY = 2000;
|
|
97
|
-
|
|
98
|
-
test.describe('/pages', () => {
|
|
99
|
-
let browser;
|
|
100
|
-
${initializePages(screenSizes)}
|
|
101
|
-
|
|
102
|
-
const delay = ms => new Promise(resolve => setTimeout(resolve, ms));
|
|
103
|
-
|
|
104
|
-
test.beforeAll(async () => {
|
|
105
|
-
// Wait until yarn start is loaded
|
|
106
|
-
test.setTimeout(60000);
|
|
107
|
-
await delay(30000);
|
|
108
|
-
browser = await chromium.launch();
|
|
109
|
-
${generateBrowserContexts(screenSizes)}
|
|
110
|
-
${generateNewPages(screenSizes)}
|
|
111
|
-
});
|
|
112
|
-
|
|
113
|
-
test.afterAll(async () => {
|
|
114
|
-
await browser.close();
|
|
115
|
-
});
|
|
116
|
-
`;
|
|
117
|
-
|
|
118
|
-
const pagesPathRegex = new RegExp(`.*${pagesFullPath.replace('/', '\\/')}(.*)`);
|
|
119
|
-
glob.sync(`${pagesFullPath}/**/*.@(${FILE_EXTENSIONS.join('|')})`).forEach((fileFullPath) => {
|
|
120
|
-
const fileRelativePath = fileFullPath.replace(pagesPathRegex, '$1');
|
|
121
|
-
const pageFileName = fileRelativePath.substring(fileRelativePath.lastIndexOf('/') + 1);
|
|
122
|
-
// Check of the file starts with letter or digit
|
|
123
|
-
if(/^[a-zA-Z0-9]/.test(pageFileName)) {
|
|
124
|
-
testFile = appendTestFile(fileRelativePath.replace(/\.[^/.]+$/, ''), testFile, screenSizes);
|
|
125
|
-
}
|
|
126
|
-
});
|
|
127
|
-
testFile += '\n});';
|
|
128
|
-
fs.writeFileSync(path.join(projectFolder, testFileName), testFile);
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
module.exports = generatePagesTestFile;
|
package/next.config.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
module.exports = require('./next.common').config
|
package/nextrc.js
DELETED
package/postcss.config.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
module.exports = require('./postcss.common').config
|
package/postcssrc.js
DELETED
package/proxy-server.js
DELETED
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
/* eslint-disable no-console */
|
|
2
|
-
const express = require('express');
|
|
3
|
-
const next = require('next');
|
|
4
|
-
const { resolveProject, extractCommandArgs } = require('@digigov/cli/lib');
|
|
5
|
-
const project = resolveProject();
|
|
6
|
-
const devProxy = project.digigov.proxy;
|
|
7
|
-
const path = require('path');
|
|
8
|
-
const port = parseInt(process.env.PORT, 10) || 3000;
|
|
9
|
-
const env = process.env.NODE_ENV;
|
|
10
|
-
const dev = env !== 'production';
|
|
11
|
-
const conf = require(path.join(project.root, 'next.config.js'));
|
|
12
|
-
const app = next({
|
|
13
|
-
dir: project.root, // base directory where everything is, could move to src later
|
|
14
|
-
dev,
|
|
15
|
-
conf,
|
|
16
|
-
});
|
|
17
|
-
const handle = app.getRequestHandler();
|
|
18
|
-
|
|
19
|
-
const commandConfig = {
|
|
20
|
-
'-p': {
|
|
21
|
-
var: 'port',
|
|
22
|
-
type: Number,
|
|
23
|
-
default: 3000,
|
|
24
|
-
},
|
|
25
|
-
};
|
|
26
|
-
const commandArgs = process.argv.slice(2)
|
|
27
|
-
const vars = extractCommandArgs(commandConfig, commandArgs)
|
|
28
|
-
|
|
29
|
-
app
|
|
30
|
-
.prepare()
|
|
31
|
-
.then(() => {
|
|
32
|
-
const server = express();
|
|
33
|
-
|
|
34
|
-
// Set up the proxy.
|
|
35
|
-
if (dev && devProxy) {
|
|
36
|
-
const { createProxyMiddleware } = require('http-proxy-middleware');
|
|
37
|
-
Object.keys(devProxy).forEach(function(context) {
|
|
38
|
-
server.use(createProxyMiddleware(context, devProxy[context]));
|
|
39
|
-
});
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
// Default catch-all handler to allow Next.js to handle all other routes
|
|
43
|
-
server.all('*', (req, res) => handle(req, res));
|
|
44
|
-
|
|
45
|
-
server.listen(vars.port, err => {
|
|
46
|
-
if (err) {
|
|
47
|
-
throw err;
|
|
48
|
-
}
|
|
49
|
-
console.log(`> Ready on port ${port}`);
|
|
50
|
-
});
|
|
51
|
-
})
|
|
52
|
-
.catch(err => {
|
|
53
|
-
console.log('An error occurred, unable to start the server');
|
|
54
|
-
console.log(err);
|
|
55
|
-
});
|