simplify core test scaffold, add default setup

This commit is contained in:
Ron Rennick 2021-12-08 16:56:53 -04:00
parent 2698cb36ff
commit 036ab6a464
6 changed files with 33 additions and 176 deletions

View File

@ -1,5 +1,5 @@
module.exports = { module.exports = {
testSpecs: 'data/scaffold-tests.json', testSpecs: 'installFiles/scaffold-tests.json',
defaultJson: 'data/default-test-config.json', defaultJson: 'installFiles/default-test-config.json',
initializeSh: 'data/initialize.sh.default', initializeSh: 'installFiles/initialize.sh.default',
}; };

View File

@ -5,7 +5,6 @@
*/ */
const fs = require( 'fs' ); const fs = require( 'fs' );
const sprintf = require( 'sprintf-js' ).sprintf; const sprintf = require( 'sprintf-js' ).sprintf;
const readlineSync = require( 'readline-sync' );
/** /**
* Internal dependencies. * Internal dependencies.
@ -15,26 +14,26 @@ const {
resolvePackage, resolvePackage,
resolvePackagePath, resolvePackagePath,
} = require( '../utils' ); } = require( '../utils' );
const {
createLocalE2ePath,
confirm,
confirmLocalCopy,
installDefaults
} = require( '../utils/scaffold' );
const args = process.argv.slice( 2 ); const args = process.argv.slice( 2 );
const [ command, packageName ] = args; const [ command, packageName ] = args;
/**
* Prompt the console for confirmation.
*
* @param {string} prompt Prompt for the user.
* @param {string} choices valid responses.
* @return {string}
*/
const confirm = ( prompt, choices ) => {
const answer = readlineSync.keyIn( prompt, choices );
return answer;
};
/** /**
* Install the test scripts and sample default.json configuration * Install the test scripts and sample default.json configuration
*/ */
if ( command == 'install' ) { if ( command == 'install' ) {
// Install some environment defaults if no package is requested.
if ( ! packageName ) {
installDefaults();
return;
}
// `package` is a reserved word // `package` is a reserved word
const pkg = resolvePackage( packageName ).name; const pkg = resolvePackage( packageName ).name;
if ( ! pkg.length ) { if ( ! pkg.length ) {
@ -47,19 +46,17 @@ if ( command == 'install' ) {
// Write sample default.json // Write sample default.json
if ( defaultJson ) { if ( defaultJson ) {
const defaultJsonName = `config/default-${packageSlug}.json`; const defaultJsonName = `config/default-${packageSlug}.json`;
const defaultJsonSample = resolveLocalE2ePath( defaultJsonName ); if ( confirmLocalCopy( defaultJsonName, defaultJson, pkg ) ) {
const packageJsonSample = resolvePackagePath( defaultJson, pkg ); console.log( `Created sample test configuration to 'tests/e2e/${defaultJsonName}'.` );
fs.copyFileSync( packageJsonSample, defaultJsonSample ); }
console.log( `Created sample test configuration to 'tests/e2e/${defaultJsonName}'.` );
} }
// Write sample initialize.sh // Write sample initialize.sh
if ( initializeSh ) { if ( initializeSh ) {
const defaultInitName = `docker/${packageSlug}.sh`; const defaultInitName = `docker/${packageSlug}.sh`;
const defaultInitPath = resolveLocalE2ePath( defaultInitName ); if ( confirmLocalCopy( defaultInitName, initializeSh, pkg ) ) {
const packageInitPath = resolvePackagePath( initializeSh, pkg ); console.log( `Created sample test container initialization script to 'tests/e2e/${defaultInitName}'.` );
fs.copyFileSync( packageInitPath, defaultInitPath ); }
console.log( `Created sample test container initialization script to 'tests/e2e/${defaultInitName}'.` );
} }
if ( ! testSpecs ) { if ( ! testSpecs ) {
@ -103,15 +100,8 @@ if ( command == 'install' ) {
importLineFormat = sprintf( "import {%%s} from '%s';", pkg ); importLineFormat = sprintf( "import {%%s} from '%s';", pkg );
} }
// Create the entire folder structure if not present // Create the specs folder if not present
let specFolderPath; let specFolderPath = createLocalE2ePath( 'specs' );
const rootFolders = [ '../../tests', '../e2e', 'specs' ];
rootFolders.forEach( ( folder ) => {
specFolderPath = resolveLocalE2ePath( folder );
if ( ! fs.existsSync( specFolderPath ) ) {
fs.mkdirSync( specFolderPath );
}
} );
// Loop through folders and files to write test scripts. // Loop through folders and files to write test scripts.
for ( let f = 0; f < active.length; f++ ) { for ( let f = 0; f < active.length; f++ ) {
@ -127,12 +117,11 @@ if ( command == 'install' ) {
continue; continue;
} }
const specFolder = testFolder.name.length ? `specs/${testFolder.name}` : 'specs'; let specFolder;
specFolderPath = resolveLocalE2ePath( specFolder ); if ( testFolder.name.length ) {
specFolder = createLocalE2ePath( testFolder.name );
// Create the test folder if it doesn't exist. } else {
if ( ! fs.existsSync( specFolderPath ) ) { specFolder = specFolderPath;
fs.mkdirSync( specFolderPath );
} }
// Create the test files. // Create the test files.
@ -142,8 +131,8 @@ if ( command == 'install' ) {
continue; continue;
} }
const testFileName = `${specFolder}/${testFile.name}.${testExtension}`; const testFileName = `${testFolder.name}/${testFile.name}.${testExtension}`;
const testFilePath = resolveLocalE2ePath( testFileName ); const testFilePath = `${specFolder}/${testFile.name}.${testExtension}`;
// Check to see if file exists. // Check to see if file exists.
if ( fs.existsSync( testFilePath ) ) { if ( fs.existsSync( testFilePath ) ) {
@ -161,7 +150,7 @@ if ( command == 'install' ) {
} }
} }
console.log( 'Writing tests/e2e/' + testFileName ); console.log( 'Writing tests/e2e/specs/' + testFileName );
let buffer = [ autoGenerate ]; let buffer = [ autoGenerate ];
let testSeparator, testTerminator, importPrefix; let testSeparator, testTerminator, importPrefix;
@ -185,6 +174,5 @@ if ( command == 'install' ) {
} }
} }
} }
// @todo: deprecated files. // @todo: deprecated files.
} }

View File

@ -1,5 +1,6 @@
{ {
"url": "http://localhost:8084/", "url": "http://localhost:8084/",
"appName": "woocommerce_e2e",
"users": { "users": {
"admin": { "admin": {
"username": "admin", "username": "admin",
@ -15,133 +16,12 @@
"name": "Simple product" "name": "Simple product"
}, },
"variable": { "variable": {
"name": "Variable Product with Three Attributes", "name": "Variable Product with Three Variations"
"defaultAttributes": [
{
"id": 0,
"name": "Size",
"option": "Medium"
},
{
"id": 0,
"name": "Colour",
"option": "Blue"
}
],
"attributes": [
{
"id": 0,
"name": "Colour",
"isVisibleOnProductPage": true,
"isForVariations": true,
"options": [
"Red",
"Green",
"Blue"
],
"sortOrder": 0
},
{
"id": 0,
"name": "Size",
"isVisibleOnProductPage": true,
"isForVariations": true,
"options": [
"Small",
"Medium",
"Large"
],
"sortOrder": 0
},
{
"id": 0,
"name": "Logo",
"isVisibleOnProductPage": true,
"isForVariations": true,
"options": [
"Woo",
"WordPress"
],
"sortOrder": 0
}
]
},
"variations": [
{
"regularPrice": "19.99",
"attributes": [
{
"name": "Size",
"option": "Large"
},
{
"name": "Colour",
"option": "Red"
}
]
},
{
"regularPrice": "18.99",
"attributes": [
{
"name": "Size",
"option": "Medium"
},
{
"name": "Colour",
"option": "Green"
}
]
},
{
"regularPrice": "17.99",
"attributes": [
{
"name": "Size",
"option": "Small"
},
{
"name": "Colour",
"option": "Blue"
}
]
}
],
"grouped": {
"name": "Grouped Product with Three Children",
"groupedProducts": [
{
"name": "Base Unit",
"regularPrice": "29.99"
},
{
"name": "Add-on A",
"regularPrice": "11.95"
},
{
"name": "Add-on B",
"regularPrice": "18.97"
}
]
},
"external": {
"name": "External product",
"regularPrice": "24.99",
"buttonText": "Buy now",
"externalUrl": "https://wordpress.org/plugins/woocommerce"
}
},
"coupons": {
"percentage": {
"code": "20percent",
"discountType": "percent",
"amount": "20.00"
} }
}, },
"addresses": { "addresses": {
"admin": { "admin": {
"store": { "store": {
"email": "admin@woocommercecoree2etestsuite.com",
"firstname": "John", "firstname": "John",
"lastname": "Doe", "lastname": "Doe",
"company": "Automattic", "company": "Automattic",
@ -181,17 +61,6 @@
} }
} }
}, },
"orders": {
"basicPaidOrder": {
"paymentMethod": "cod",
"status": "processing",
"billing": {
"firstName": "John",
"lastName": "Doe",
"email": "john.doe@example.com"
}
}
},
"onboardingwizard": { "onboardingwizard": {
"industry": "Test industry", "industry": "Test industry",
"numberofproducts": "1 - 10", "numberofproducts": "1 - 10",