@telefonica/acceptance-testing 3.0.0-beta3 → 3.0.0-beta4

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.
@@ -1,3 +1,4 @@
1
+ // @ts-check
1
2
  const path = require('path');
2
3
  const fs = require('fs');
3
4
  const findRoot = require('find-root');
@@ -16,10 +17,19 @@ const poll = async (url) => {
16
17
  throw Error(`Error fetching ${url}`);
17
18
  };
18
19
 
20
+ /** @param args {Array<unknown>} */
21
+ const debug = (...args) => {
22
+ if (process.env.DEBUG) {
23
+ console.log('[acceptance-testing]', ...args);
24
+ }
25
+ };
26
+
19
27
  /**
20
28
  * CI => everything runs inside a docker
21
29
  * Local, headless => connects to a dockerized chromium at port 9223 (see docker-compose.yaml)
22
30
  * Local, with UI => launches a local chromium installed by puppetteer
31
+ *
32
+ * @returns {Promise<import('jest-environment-puppeteer').JestPuppeteerConfig>}
23
33
  */
24
34
  const getPuppeteerConfig = async () => {
25
35
  const isCi = process.argv.includes('--ci') || process.env.CI;
@@ -27,12 +37,12 @@ const getPuppeteerConfig = async () => {
27
37
  const isHeadless = !!process.env.HEADLESS;
28
38
 
29
39
  const rootDir = findRoot(process.cwd());
30
- const pkg = JSON.parse(fs.readFileSync(path.join(rootDir, 'package.json'), 'utf-8'));
31
- const projectConfig = pkg.acceptanceTests || {};
40
+ const packageJson = JSON.parse(fs.readFileSync(path.join(rootDir, 'package.json'), 'utf-8'));
41
+ const projectConfig = packageJson.acceptanceTests || {};
32
42
 
33
43
  const server = (isCi ? projectConfig.ciServer : projectConfig.devServer) || projectConfig.server || {};
34
44
 
35
- const baseConfig = {
45
+ const baseConnectOrLaunchConfig = {
36
46
  ignoreHTTPSErrors: true,
37
47
  headless: isHeadless,
38
48
  slowMo: isHeadless ? 0 : 50,
@@ -65,7 +75,7 @@ const getPuppeteerConfig = async () => {
65
75
  // const {webSocketDebuggerUrl} = await fetch(`${dockerChromiumUrl}/json/version`).then((r) => r.json());
66
76
 
67
77
  connect = {
68
- ...baseConfig,
78
+ ...baseConnectOrLaunchConfig,
69
79
  browserURL: dockerChromiumUrl,
70
80
  // browserWSEndpoint: webSocketDebuggerUrl,
71
81
  };
@@ -80,40 +90,45 @@ const getPuppeteerConfig = async () => {
80
90
  launchTimeout: 60000,
81
91
  };
82
92
 
83
- return {
84
- launch: {
85
- ...baseConfig,
86
- // Launch chromium installed in docker in CI
87
- ...(isCi ? {executablePath: '/usr/bin/chromium'} : {}),
88
- env: {
89
- ...process.env,
90
- TZ: 'UTC',
91
- LANG: 'es_ES',
92
- LANGUAGE: 'es_ES',
93
- },
94
- args: [
95
- // https://peter.sh/experiments/chromium-command-line-switches/
96
- '--no-sandbox', // probably not needed in ubuntu
97
- '--font-render-hinting=none', // this flag is important because we use it when launching dockerized chromium too
98
- '--disable-background-networking',
99
- '--disable-background-timer-throttling',
100
- '--disable-breakpad',
101
- '--disable-client-side-phishing-detection',
102
- '--disable-default-apps',
103
- '--disable-dev-shm-usage',
104
- '--disable-extensions',
105
- '--disable-features=site-per-process',
106
- '--disable-hang-monitor',
107
- '--disable-popup-blocking',
108
- '--disable-prompt-on-repost',
109
- '--disable-sync',
110
- '--disable-translate',
111
- '--disable-smooth-scrolling',
112
- ],
113
- },
93
+ /** @type import('jest-environment-puppeteer').JestPuppeteerConfig */
94
+ const config = {
95
+ // launch: {
96
+ // ...baseConnectOrLaunchConfig,
97
+ // // Launch chromium installed in docker in CI
98
+ // // ...(isCi ? {executablePath: '/usr/bin/chromium'} : {}),
99
+ // env: {
100
+ // TZ: 'UTC',
101
+ // LANG: 'es_ES',
102
+ // LANGUAGE: 'es_ES',
103
+ // },
104
+ // args: [
105
+ // // https://peter.sh/experiments/chromium-command-line-switches/
106
+ // '--no-sandbox', // probably not needed in ubuntu
107
+ // '--font-render-hinting=none', // this flag is important because we use it when launching dockerized chromium too
108
+ // '--disable-background-networking',
109
+ // '--disable-background-timer-throttling',
110
+ // '--disable-breakpad',
111
+ // '--disable-client-side-phishing-detection',
112
+ // '--disable-default-apps',
113
+ // '--disable-dev-shm-usage',
114
+ // '--disable-extensions',
115
+ // '--disable-features=site-per-process',
116
+ // '--disable-hang-monitor',
117
+ // '--disable-popup-blocking',
118
+ // '--disable-prompt-on-repost',
119
+ // '--disable-sync',
120
+ // '--disable-translate',
121
+ // '--disable-smooth-scrolling',
122
+ // ],
123
+ // },
114
124
  browserContext: 'incognito',
115
125
  browserPerWorker: false,
116
- connect,
126
+ connect: {
127
+ ...baseConnectOrLaunchConfig,
128
+ browserURL: 'http://localhost:9222',
129
+ // browserWSEndpoint: (await fetch(`${'http://localhost:9223'}/json/version`).then((r) => r.json()))
130
+ // .webSocketDebuggerUrl,
131
+ },
117
132
  server: server
118
133
  ? {
119
134
  ...defaultServerConfig,
@@ -121,6 +136,9 @@ const getPuppeteerConfig = async () => {
121
136
  }
122
137
  : undefined,
123
138
  };
139
+
140
+ debug('jest-puppeteer-config', config);
141
+ return config;
124
142
  };
125
143
 
126
144
  module.exports = getPuppeteerConfig();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@telefonica/acceptance-testing",
3
- "version": "3.0.0-beta3",
3
+ "version": "3.0.0-beta4",
4
4
  "author": "Telefonica",
5
5
  "license": "UNLICENSED",
6
6
  "module": "dist/acceptance-testing.esm.js",
@@ -32,6 +32,7 @@
32
32
  "@typescript-eslint/eslint-plugin": "^7.9.0",
33
33
  "@typescript-eslint/parser": "^7.9.0",
34
34
  "babel-jest": "^29.7.0",
35
+ "jest-environment-puppeteer": "^10.0.1",
35
36
  "tsdx": "^0.14.1",
36
37
  "tslib": "^2.6.2",
37
38
  "typescript": "^5.4.5"