Skip to content

Commit

Permalink
style: updated with new eslint and prettier rulesets
Browse files Browse the repository at this point in the history
  • Loading branch information
ampersarnie committed Dec 16, 2021
1 parent 58c23fa commit 802337c
Show file tree
Hide file tree
Showing 18 changed files with 140 additions and 117 deletions.
13 changes: 10 additions & 3 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"extends": ["airbnb-base"],
"plugins": ["cypress"],
"extends": ["airbnb-base", "prettier"],
"plugins": ["cypress", "prettier"],
"ignorePatterns": ["lib/cypress-plugin/tmp/*"],
"env": {
"browser": true,
Expand All @@ -9,6 +9,13 @@
},
"parser": "babel-eslint",
"rules": {
"import/no-extraneous-dependencies": ["error", { "devDependencies": true }]
"prettier/prettier": "error",
"import/no-extraneous-dependencies": [
"error",
{
"devDependencies": true
}
],
"arrow-parens": 2
}
}
6 changes: 6 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"printWidth": 100,
"trailingComma": "all",
"arrowParens": "always",
"singleQuote": true
}
38 changes: 26 additions & 12 deletions lib/cli/commands/reset.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,7 @@ const getWPInstallType = require('../../modules/getWPInstallType');
const reset = async (packageDir, logFile, options) => {
const config = fs.readJsonSync(`${packageDir}/config.json`);

const version = (options && isString(options.version))
? options.version
: config.validVersions[0];
const version = options && isString(options.version) ? options.version : config.validVersions[0];

shell.cd(packageDir);

Expand All @@ -32,7 +30,9 @@ const reset = async (packageDir, logFile, options) => {
const locale = get(config, ['locale'], 'en_US');

await run(
async () => wpcli(`core config \
async () =>
wpcli(
`core config \
--dbhost=db \
--dbname=wordpress \
--dbuser=root \
Expand All @@ -41,8 +41,11 @@ const reset = async (packageDir, logFile, options) => {
--extra-php <<PHP
define( 'FS_METHOD', 'direct' );
${map(config.config, (value, key) => `
define( '${key}', ${isString(value) ? `'${value}'` : value} );`).join('')}
${map(
config.config,
(value, key) => `
define( '${key}', ${isString(value) ? `'${value}'` : value} );`,
).join('')}
if ( file_exists( __DIR__ . '/wp-cypress-config.php' ) ) {
require_once __DIR__ . '/wp-cypress-config.php';
Expand All @@ -55,7 +58,9 @@ if( file_exists ( ABSPATH . '.userid' ) ) {
}
PHP
`, logFile),
`,
logFile,
),
'Creating wp-config.php',
'wp-config.php created',
logFile,
Expand All @@ -69,10 +74,13 @@ PHP
);

await run(
async () => wpcli(
`core ${getWPInstallType(config.multisite)} --url=${config.url} --title="WP Cypress" --admin_user=admin --admin_password=password --admin_email="[email protected]" --skip-email`,
logFile,
),
async () =>
wpcli(
`core ${getWPInstallType(config.multisite)} --url=${
config.url
} --title="WP Cypress" --admin_user=admin --admin_password=password --admin_email="[email protected]" --skip-email`,
logFile,
),
'Installing WordPress',
'WordPress installed',
logFile,
Expand All @@ -88,7 +96,13 @@ PHP
}

await run(
async () => wpcli(`plugin activate wp-cypress ${config.activePlugins.join(' ')} ${config.multisite ? '--network' : ''}`, logFile),
async () =>
wpcli(
`plugin activate wp-cypress ${config.activePlugins.join(' ')} ${
config.multisite ? '--network' : ''
}`,
logFile,
),
'Activating plugins',
'Activated plugins',
logFile,
Expand Down
4 changes: 1 addition & 3 deletions lib/cli/commands/softReset.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,7 @@ const run = require('../../modules/run');
const softReset = async (packageDir, logFile, options = false) => {
const config = fs.readJsonSync(`${packageDir}/config.json`);

const version = (options && isString(options.version))
? options.version
: config.validVersions[0];
const version = options && isString(options.version) ? options.version : config.validVersions[0];

shell.cd(packageDir);

Expand Down
14 changes: 6 additions & 8 deletions lib/cli/commands/start.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,11 @@ const start = async (packageDir, options, logFile) => {
shell.cd(packageDir);

await run(
async () => exec(
'docker-compose down --volumes && docker-compose build && docker-compose up -d',
logFile,
),
async () =>
exec(
'docker-compose down --volumes && docker-compose build && docker-compose up -d',
logFile,
),
'Creating test container',
'Test container created',
logFile,
Expand All @@ -45,10 +46,7 @@ const start = async (packageDir, options, logFile) => {
);

await run(
async () => cli(
'composer install -d /var/www/html/wp-content/plugins/wp-cypress',
logFile,
),
async () => cli('composer install -d /var/www/html/wp-content/plugins/wp-cypress', logFile),
'Installing wp-cypress dependencies',
'Dependencies installed',
logFile,
Expand Down
5 changes: 1 addition & 4 deletions lib/cli/commands/wp.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,7 @@ const run = require('../../modules/run');
const wp = async (command, packageDir, logFile) => {
shell.cd(packageDir);

await run(
async () => wpcli(command, logFile),
`Running wp ${command}`,
);
await run(async () => wpcli(command, logFile), `Running wp ${command}`);
};

module.exports = wp;
9 changes: 3 additions & 6 deletions lib/cli/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,13 @@ program

program
.command('reset')
.description('Hard reset the installation to it\'s initial state')
.description("Hard reset the installation to it's initial state")
.option('-v,--version <version>')
.action((options) => reset(packageDir, logFile, options));

program
.command('soft-reset')
.description('Soft reset the installation to it\'s initial state')
.description("Soft reset the installation to it's initial state")
.option('-v,--version <version>')
.action((options) => softReset(packageDir, logFile, options));

Expand All @@ -48,10 +48,7 @@ program
.command('seed')
.description('Execute WordPress CLI seed command.')
.option('<seeder>', 'The name of the seeder to run.')
.option(
'-cf, --clean-first',
'Whether to run the clean routine before seeding.',
)
.option('-cf, --clean-first', 'Whether to run the clean routine before seeding.')
.option('-c, --clean', 'Run only the seeder clean routine.')
.action((options) => {
let cleanFlag = '';
Expand Down
4 changes: 3 additions & 1 deletion lib/cypress-plugin/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,9 @@ module.exports = async (_on, config) => {
watchDir(config.integrationFolder, duplicateTests);
}

const baseUrl = packageConfig.port ? `http://localhost:${packageConfig.port}` : 'http://localhost';
const baseUrl = packageConfig.port
? `http://localhost:${packageConfig.port}`
: 'http://localhost';

return {
...config,
Expand Down
6 changes: 4 additions & 2 deletions lib/cypress-plugin/modifySpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ module.exports = (fileContents, version, source, target) => {
});
`).body[0];


const parsed = esprima.parseModule(fileContents);

const parsedFileWithInsert = {
Expand Down Expand Up @@ -64,7 +63,10 @@ module.exports = (fileContents, version, source, target) => {
return block;
}

if (block.expression.callee.name === 'describe' || block.expression.callee.name === 'context') {
if (
block.expression.callee.name === 'describe' ||
block.expression.callee.name === 'context'
) {
block.expression.arguments[0].value = `[${version}] ${block.expression.arguments[0].value}`;
block.expression.arguments[0].raw = `[${version}] ${block.expression.arguments[0].value}`;
block.expression.arguments[1].body.body = [
Expand Down
16 changes: 7 additions & 9 deletions lib/cypress-support/commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,25 +13,23 @@ const commands = {
},

seedClean(seeder) {
cy.exec(`node_modules/.bin/wp-cypress wp "seed ${seeder} --clean"`).then(
(result) => {
cy.log(result.stdout);
},
);
cy.exec(`node_modules/.bin/wp-cypress wp "seed ${seeder} --clean"`).then((result) => {
cy.log(result.stdout);
});
},

cleanThenSeed(seeder) {
cy.exec(
`node_modules/.bin/wp-cypress wp "seed ${seeder} --clean-first"`,
).then((result) => {
cy.exec(`node_modules/.bin/wp-cypress wp "seed ${seeder} --clean-first"`).then((result) => {
cy.log(result.stdout);
});
},

resetWP(version = false) {
const wpVersion = version || (Cypress.wp || {}).version || false;
cy.log('WP Cypress: performing full teardown...');
cy.exec(`node_modules/.bin/wp-cypress soft-reset ${wpVersion ? `--version='${wpVersion}'` : ''}`);
cy.exec(
`node_modules/.bin/wp-cypress soft-reset ${wpVersion ? `--version='${wpVersion}'` : ''}`,
);
},

installTheme(name) {
Expand Down
18 changes: 8 additions & 10 deletions lib/cypress-support/setSelection.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@ const getTextNode = (el, match) => {

let node;

// eslint-disable-next-line no-cond-assign
while (node = walk.nextNode()) {
while ((node = walk.nextNode())) {
if (node.wholeText.includes(match)) {
return node;
}
Expand All @@ -23,21 +22,20 @@ const getTextNode = (el, match) => {
return false;
};

Cypress.Commands.add('setSelection', { prevSubject: true }, (subject, query, endQuery) => cy.wrap(subject)
.selection(($el) => {
Cypress.Commands.add('setSelection', { prevSubject: true }, (subject, query, endQuery) =>
cy.wrap(subject).selection(($el) => {
const anchorNode = getTextNode($el[0], query);
const focusNode = endQuery ? getTextNode($el[0], endQuery) : anchorNode;
const anchorOffset = anchorNode.wholeText.indexOf(query);
const focusOffset = endQuery ? focusNode.wholeText.indexOf(endQuery) + endQuery.length
const focusOffset = endQuery
? focusNode.wholeText.indexOf(endQuery) + endQuery.length
: anchorOffset + query.length;
setBaseAndExtent(anchorNode, anchorOffset, focusNode, focusOffset);
}));
}),
);

Cypress.Commands.add('selection', { prevSubject: true }, (subject, fn) => {
cy.wrap(subject)
.trigger('mousedown')
.then(fn)
.trigger('mouseup');
cy.wrap(subject).trigger('mousedown').then(fn).trigger('mouseup');

cy.document().trigger('selectionchange');
return cy.wrap(subject);
Expand Down
9 changes: 5 additions & 4 deletions lib/modules/copyVolumes.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,11 @@ const copyToContainer = async (location, destination, logFile) => {
const name = path.basename(destination);
// eslint-disable-next-line no-await-in-loop
await run(
async () => exec(
`docker cp ${location} $(docker ps | awk 'NR > 1 {print $1; exit}'):${destination}`,
logFile,
),
async () =>
exec(
`docker cp ${location} $(docker ps | awk 'NR > 1 {print $1; exit}'):${destination}`,
logFile,
),
`Copying ${name}`,
`Copied ${name}`,
logFile,
Expand Down
39 changes: 15 additions & 24 deletions lib/modules/createConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,7 @@ const WP_CONTENT_EXCLUDE_PATHS = ['uploads', 'upgrade', 'node_modules', 'cypress
const createConfig = async (packageDir, hasVolumeSupport = true) => {
const CWD = process.cwd();

const {
wp = {},
integrationFolder,
} = await fs.readJSON(`${CWD}/cypress.json`);
const { wp = {}, integrationFolder } = await fs.readJSON(`${CWD}/cypress.json`);

const config = defaults(wp, {
seedsPath: 'cypress/seeds',
Expand All @@ -42,10 +39,12 @@ const createConfig = async (packageDir, hasVolumeSupport = true) => {
const schema = await fs.readJSON(`${packageDir}/lib/schemas/config-validation.json`);

if (!validation.validate(schema, config)) {
throw new Error([
validation.errors[0].message,
...[get(validation.errors[0], 'params.errors[0].message') || ''],
].join(', '));
throw new Error(
[
validation.errors[0].message,
...[get(validation.errors[0], 'params.errors[0].message') || ''],
].join(', '),
);
}

if (!config.url) {
Expand Down Expand Up @@ -92,11 +91,7 @@ const createConfig = async (packageDir, hasVolumeSupport = true) => {
activeTheme = themes[0].name;
}

volumes = [
...volumes,
...(plugins.map((x) => x.volume)),
...(themes.map((x) => x.volume)),
];
volumes = [...volumes, ...plugins.map((x) => x.volume), ...themes.map((x) => x.volume)];
}

const seedsDir = `${CWD}/${config.seedsPath}`;
Expand Down Expand Up @@ -139,17 +134,13 @@ const createConfig = async (packageDir, hasVolumeSupport = true) => {
htaccessFile = `${htaccessFile}-subfolder`;
}

await renderTemplate(
`${packageDir}/lib/templates/dockerfile.ejs`,
`${packageDir}/Dockerfile`,
{
isWpContent: config.wpContent,
versions: validVersions,
vip: config.muPlugins ? config.muPlugins.vip : false,
phpVersion: config.phpVersion || 7.3,
htaccessFile,
},
);
await renderTemplate(`${packageDir}/lib/templates/dockerfile.ejs`, `${packageDir}/Dockerfile`, {
isWpContent: config.wpContent,
versions: validVersions,
vip: config.muPlugins ? config.muPlugins.vip : false,
phpVersion: config.phpVersion || 7.3,
htaccessFile,
});

const wpCypressConfig = {
...config,
Expand Down
Loading

0 comments on commit 802337c

Please sign in to comment.