@tramvai/test-pw 7.5.1 → 7.7.0

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.
@@ -17,7 +17,9 @@ export type AppServerOptionsType = {
17
17
  export declare namespace BuildAppTypes {
18
18
  type Cwd = string;
19
19
  type AppTarget = _AppTarget;
20
- type BuildOptions = BuildCliOptions;
20
+ type BuildOptions = BuildCliOptions & {
21
+ appPrerenderEnabled?: boolean;
22
+ };
21
23
  type AppServer = AppServerType;
22
24
  type AppServerOptions = AppServerOptionsType;
23
25
  }
@@ -47,6 +49,7 @@ export declare const appServerFixture: [
47
49
  appTarget: BuildAppTypes.AppTarget;
48
50
  appServerOptions: BuildAppTypes.AppServerOptions;
49
51
  buildApp: void;
52
+ buildOptions?: BuildAppTypes.BuildOptions;
50
53
  }>,
51
54
  {
52
55
  scope: 'test';
@@ -1,6 +1,6 @@
1
1
  import mergeDeep from '@tinkoff/utils/object/mergeDeep';
2
2
  import path from 'path';
3
- import { node } from 'execa';
3
+ import execa, { node } from 'execa';
4
4
  import waitOn from 'wait-on';
5
5
  import getPort from 'get-port';
6
6
  import { buildCli } from '@tramvai/test-integration';
@@ -12,6 +12,8 @@ import { buildCli } from '@tramvai/test-integration';
12
12
  */
13
13
  const buildAppFixture = [
14
14
  async ({ appTarget, buildOptions }, use) => {
15
+ const rootDir = appTarget.cwd ?? path.dirname(path.resolve(module.parent.filename, '.'));
16
+ const { appPrerenderEnabled, ...options } = buildOptions ?? {};
15
17
  await buildCli('target' in appTarget
16
18
  ? appTarget.target
17
19
  : mergeDeep(appTarget.config, {
@@ -19,8 +21,8 @@ const buildAppFixture = [
19
21
  type: 'application',
20
22
  root: appTarget.cwd,
21
23
  }), {
22
- ...buildOptions,
23
- rootDir: appTarget.cwd ?? path.dirname(path.resolve(module.parent.filename, '.')),
24
+ ...options,
25
+ rootDir,
24
26
  });
25
27
  await use();
26
28
  // @todo clear dist?
@@ -34,7 +36,8 @@ const buildAppFixture = [
34
36
  * @returns возвращает свойства запущенного сервера (порт приложения, порт по которому доступны ассеты)
35
37
  */
36
38
  const appServerFixture = [
37
- async ({ appTarget, appServerOptions, buildApp }, use) => {
39
+ // eslint-disable-next-line max-statements
40
+ async ({ appTarget, appServerOptions, buildApp, buildOptions }, use) => {
38
41
  const { env = {}, output = {} } = appServerOptions;
39
42
  const root = appTarget.cwd ?? path.dirname(path.resolve(module.parent.filename, '.'));
40
43
  const port = await getPort();
@@ -42,6 +45,34 @@ const appServerFixture = [
42
45
  const readinessProbePath = `http://localhost:${port}/readyz`;
43
46
  const clientOutput = output.client ?? path.join('dist', 'client');
44
47
  const serverOutput = output.server ?? path.join('dist', 'server');
48
+ const { appPrerenderEnabled = false, ...options } = buildOptions ?? {};
49
+ const sharedEnv = {
50
+ PORT: String(port),
51
+ PORT_STATIC: String(staticPort),
52
+ NODE_ENV: 'production',
53
+ CACHE_WARMUP_DISABLED: 'true',
54
+ DEV_STATIC: 'true',
55
+ DANGEROUS_UNSAFE_ENV_FILES: 'true',
56
+ ASSETS_PREFIX: `http://localhost:${staticPort}/${clientOutput}/`,
57
+ ...env,
58
+ };
59
+ if (appPrerenderEnabled) {
60
+ // TODO: JS API for tramvai static
61
+ await execa('tramvai', [
62
+ 'static',
63
+ 'target' in appTarget ? appTarget.target : appTarget.name,
64
+ '--buildType',
65
+ 'none',
66
+ ], {
67
+ cwd: root,
68
+ env: {
69
+ ...process.env,
70
+ ...options?.env,
71
+ ...sharedEnv,
72
+ DANGEROUS_UNSAFE_ENV_FILES: 'true',
73
+ },
74
+ });
75
+ }
45
76
  const server = node(path.resolve(root, serverOutput, 'server.js'), [], {
46
77
  cwd: root,
47
78
  env: {
@@ -13,6 +13,7 @@ function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'defau
13
13
 
14
14
  var mergeDeep__default = /*#__PURE__*/_interopDefaultLegacy(mergeDeep);
15
15
  var path__default = /*#__PURE__*/_interopDefaultLegacy(path);
16
+ var execa__default = /*#__PURE__*/_interopDefaultLegacy(execa);
16
17
  var waitOn__default = /*#__PURE__*/_interopDefaultLegacy(waitOn);
17
18
  var getPort__default = /*#__PURE__*/_interopDefaultLegacy(getPort);
18
19
 
@@ -23,6 +24,8 @@ var getPort__default = /*#__PURE__*/_interopDefaultLegacy(getPort);
23
24
  */
24
25
  const buildAppFixture = [
25
26
  async ({ appTarget, buildOptions }, use) => {
27
+ const rootDir = appTarget.cwd ?? path__default["default"].dirname(path__default["default"].resolve(module.parent.filename, '.'));
28
+ const { appPrerenderEnabled, ...options } = buildOptions ?? {};
26
29
  await testIntegration.buildCli('target' in appTarget
27
30
  ? appTarget.target
28
31
  : mergeDeep__default["default"](appTarget.config, {
@@ -30,8 +33,8 @@ const buildAppFixture = [
30
33
  type: 'application',
31
34
  root: appTarget.cwd,
32
35
  }), {
33
- ...buildOptions,
34
- rootDir: appTarget.cwd ?? path__default["default"].dirname(path__default["default"].resolve(module.parent.filename, '.')),
36
+ ...options,
37
+ rootDir,
35
38
  });
36
39
  await use();
37
40
  // @todo clear dist?
@@ -45,7 +48,8 @@ const buildAppFixture = [
45
48
  * @returns возвращает свойства запущенного сервера (порт приложения, порт по которому доступны ассеты)
46
49
  */
47
50
  const appServerFixture = [
48
- async ({ appTarget, appServerOptions, buildApp }, use) => {
51
+ // eslint-disable-next-line max-statements
52
+ async ({ appTarget, appServerOptions, buildApp, buildOptions }, use) => {
49
53
  const { env = {}, output = {} } = appServerOptions;
50
54
  const root = appTarget.cwd ?? path__default["default"].dirname(path__default["default"].resolve(module.parent.filename, '.'));
51
55
  const port = await getPort__default["default"]();
@@ -53,6 +57,34 @@ const appServerFixture = [
53
57
  const readinessProbePath = `http://localhost:${port}/readyz`;
54
58
  const clientOutput = output.client ?? path__default["default"].join('dist', 'client');
55
59
  const serverOutput = output.server ?? path__default["default"].join('dist', 'server');
60
+ const { appPrerenderEnabled = false, ...options } = buildOptions ?? {};
61
+ const sharedEnv = {
62
+ PORT: String(port),
63
+ PORT_STATIC: String(staticPort),
64
+ NODE_ENV: 'production',
65
+ CACHE_WARMUP_DISABLED: 'true',
66
+ DEV_STATIC: 'true',
67
+ DANGEROUS_UNSAFE_ENV_FILES: 'true',
68
+ ASSETS_PREFIX: `http://localhost:${staticPort}/${clientOutput}/`,
69
+ ...env,
70
+ };
71
+ if (appPrerenderEnabled) {
72
+ // TODO: JS API for tramvai static
73
+ await execa__default["default"]('tramvai', [
74
+ 'static',
75
+ 'target' in appTarget ? appTarget.target : appTarget.name,
76
+ '--buildType',
77
+ 'none',
78
+ ], {
79
+ cwd: root,
80
+ env: {
81
+ ...process.env,
82
+ ...options?.env,
83
+ ...sharedEnv,
84
+ DANGEROUS_UNSAFE_ENV_FILES: 'true',
85
+ },
86
+ });
87
+ }
56
88
  const server = execa.node(path__default["default"].resolve(root, serverOutput, 'server.js'), [], {
57
89
  cwd: root,
58
90
  env: {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tramvai/test-pw",
3
- "version": "7.5.1",
3
+ "version": "7.7.0",
4
4
  "description": "",
5
5
  "main": "lib/index.js",
6
6
  "typings": "lib/index.d.ts",
@@ -18,8 +18,8 @@
18
18
  },
19
19
  "dependencies": {
20
20
  "@tinkoff/utils": "^2.1.2",
21
- "@tramvai/test-integration": "7.5.1",
22
- "@tramvai/tokens-router": "7.5.1",
21
+ "@tramvai/test-integration": "7.7.0",
22
+ "@tramvai/tokens-router": "7.7.0",
23
23
  "console-with-style": "^1.1.0",
24
24
  "env-ci": "^5.0.2",
25
25
  "execa": "^5.1.1",
@@ -33,7 +33,7 @@
33
33
  },
34
34
  "devDependencies": {
35
35
  "@playwright/test": "1.54.1",
36
- "@tramvai/cli": "7.5.1",
36
+ "@tramvai/cli": "7.7.0",
37
37
  "@types/env-ci": "^3.1.0",
38
38
  "@types/supports-color": "^8.1.1",
39
39
  "@types/wait-on": "^5.2.0",