use @automattic/puppeteer-utils

This commit is contained in:
Ron Rennick 2020-07-28 16:23:32 -03:00
parent e78beaf569
commit d9e9faaa44
5 changed files with 22 additions and 29 deletions

View File

@ -5,6 +5,7 @@ const program = require( 'commander' );
const path = require( 'path' ); const path = require( 'path' );
const fs = require( 'fs' ); const fs = require( 'fs' );
const getAppPath = require( '../utils/app-root' ); const getAppPath = require( '../utils/app-root' );
const { JEST_PUPPETEER_CONFIG } = process.env;
program program
.usage( '<file ...> [options]' ) .usage( '<file ...> [options]' )
@ -23,16 +24,18 @@ if ( appPath ) {
); );
} }
const testEnvVars = { let testEnvVars = {
NODE_ENV: 'test-e2e', NODE_ENV: 'test-e2e',
JEST_PUPPETEER_CONFIG: path.resolve(
__dirname,
'../config/jest-puppeteer.config.js'
),
NODE_CONFIG_DIR: nodeConfigDirs.join( ':' ), NODE_CONFIG_DIR: nodeConfigDirs.join( ':' ),
node_config_dev: program.dev ? 'yes' : 'no', node_config_dev: program.dev ? 'yes' : 'no',
jest_test_timeout: program.dev ? 120000 : 30000, jest_test_timeout: program.dev ? 120000 : 30000,
}; };
if ( ! JEST_PUPPETEER_CONFIG ) {
testEnvVars.JEST_PUPPETEER_CONFIG = path.resolve(
__dirname,
'../config/jest-puppeteer.config.js'
);
}
let jestCommand = 'jest'; let jestCommand = 'jest';
const jestArgs = [ const jestArgs = [

View File

@ -9,7 +9,8 @@ DELAY_SEC=10
# Counter for the loop that checks if the Docker container had been built # Counter for the loop that checks if the Docker container had been built
count=0 count=0
WP_BASE_URL=$(node utils/get-base-url.js) WP_BASE_URL=$(node utils/get-base-url.js)
echo "Testing URL: $WP_BASE_URL" printf "Testing URL: $WP_BASE_URL\n\n"
while [[ "$(curl -s -o /dev/null -w ''%{http_code}'' ${WP_BASE_URL}/?pagename=ready)" != "200" ]] while [[ "$(curl -s -o /dev/null -w ''%{http_code}'' ${WP_BASE_URL}/?pagename=ready)" != "200" ]]
do do

View File

@ -1,5 +1,5 @@
{ {
"url": "http://localhost:8085/", "url": "http://localhost:8084/",
"users": { "users": {
"admin": { "admin": {
"username": "admin", "username": "admin",

View File

@ -1,28 +1,21 @@
/** @format */ /** @format */
const { jestPuppeteerConfig } = require( '@automattic/puppeteer-utils' );
let puppeteerConfig; let puppeteerConfig;
if ( 'no' == global.process.env.node_config_dev ) { if ( 'no' == global.process.env.node_config_dev ) {
puppeteerConfig = { puppeteerConfig = jestPuppeteerConfig;
launch: {
// Required for the logged out and logged in tests so they don't share app state/token.
browserContext: 'incognito',
},
};
} else { } else {
puppeteerConfig = { puppeteerConfig = {
launch: { launch: {
slowMo: process.env.PUPPETEER_SLOWMO ? false : 50, ...jestPuppeteerConfig.launch,
headless: process.env.PUPPETEER_HEADLESS || false,
ignoreHTTPSErrors: true, ignoreHTTPSErrors: true,
args: [ '--window-size=1920,1080', '--user-agent=chrome' ], args: [ '--window-size=1920,1080', '--user-agent=chrome' ],
devtools: true, devtools: true,
defaultViewport: { defaultViewport: {
width: 1280, width: 1280,
height: 800, height: 800,
}, }
// Required for the logged out and logged in tests so they don't share app state/token.
browserContext: 'incognito',
}, },
}; };
} }

View File

@ -1,17 +1,12 @@
const { jestConfig } = require( '@automattic/puppeteer-utils' );
module.exports = { module.exports = {
// Automatically clear mock calls and instances between every test ...jestConfig,
clearMocks: true,
// An array of file extensions your modules use
moduleFileExtensions: [ 'js' ],
moduleNameMapper: { moduleNameMapper: {
'@woocommerce/e2e-tests/(.*)': '@woocommerce/e2e-tests/(.*)':
'<rootDir>/tests/e2e/$1', '<rootDir>/tests/e2e/$1',
}, },
preset: 'jest-puppeteer',
setupFiles: [ '<rootDir>/config/env.setup.js' ], setupFiles: [ '<rootDir>/config/env.setup.js' ],
// A list of paths to modules that run some code to configure or set up the testing framework // A list of paths to modules that run some code to configure or set up the testing framework
// before each test // before each test
@ -20,12 +15,13 @@ module.exports = {
'expect-puppeteer', 'expect-puppeteer',
], ],
// The glob patterns Jest uses to detect test files
testMatch: [ '**/*.(test|spec).js' ],
// Sort test path alphabetically. This is needed so that `activate-and-setup` tests run first // Sort test path alphabetically. This is needed so that `activate-and-setup` tests run first
testSequencer: '<rootDir>/config/jest-custom-sequencer.js', testSequencer: '<rootDir>/config/jest-custom-sequencer.js',
// Set the test timeout in milliseconds. // Set the test timeout in milliseconds.
testTimeout: parseInt( global.process.env.jest_test_timeout ), testTimeout: parseInt( global.process.env.jest_test_timeout ),
transformIgnorePatterns: [ 'node_modules/(?!(woocommerce)/)' ], transformIgnorePatterns: [
...jestConfig.transformIgnorePatterns,
'node_modules/(?!(woocommerce)/)'
],
}; };