Skip to content

Commit b4b3e7f

Browse files
authored
Merge pull request #82 from mirkootter/master
Add Windows Support
2 parents 4f4de7c + efe3051 commit b4b3e7f

File tree

3 files changed

+42
-34
lines changed

3 files changed

+42
-34
lines changed

lib/cli/commands/reset.js

+7-12
Original file line numberDiff line numberDiff line change
@@ -32,14 +32,10 @@ const reset = async (packageDir, logFile, options) => {
3232
const locale = get(config, ['locale'], 'en_US');
3333

3434
await run(
35-
async () => wpcli(`core config \
36-
--dbhost=db \
37-
--dbname=wordpress \
38-
--dbuser=root \
39-
--dbpass='' \
40-
--locale=${locale} \
41-
--extra-php <<PHP
42-
define( 'FS_METHOD', 'direct' );
35+
async () => wpcli(
36+
`core config --dbhost=db --dbname=wordpress --dbuser=root --dbpass="" --locale=${locale} --extra-php`,
37+
logFile,
38+
`define( 'FS_METHOD', 'direct' );
4339
4440
${map(config.config, (value, key) => `
4541
define( '${key}', ${isString(value) ? `'${value}'` : value} );`).join('')}
@@ -49,13 +45,12 @@ if ( file_exists( __DIR__ . '/wp-cypress-config.php' ) ) {
4945
}
5046
5147
if( file_exists ( ABSPATH . '.userid' ) ) {
52-
function wp_validate_auth_cookie( \\$cookie='', \\$scheme='' ) {
48+
function wp_validate_auth_cookie( $cookie='', $scheme='' ) {
5349
return file_get_contents( ABSPATH . '.userid' );
5450
}
5551
}
56-
57-
PHP
58-
`, logFile),
52+
`,
53+
),
5954
'Creating wp-config.php',
6055
'wp-config.php created',
6156
logFile,

lib/cypress-support/commands.js

+16-13
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,22 @@
11
require('./hooks');
22
require('./setSelection');
33

4+
const wpCypress = Cypress.platform === 'win32'
5+
? 'node_modules\\.bin\\wp-cypress' : 'node_modules/.bin/wp-cypress';
6+
47
const commands = {
58
wp(command) {
6-
cy.exec(`node_modules/.bin/wp-cypress wp "${command}"`);
9+
cy.exec(`${wpCypress} wp "${command}"`);
710
},
811

912
seed(seeder) {
10-
cy.exec(`node_modules/.bin/wp-cypress wp "seed ${seeder}"`).then((result) => {
13+
cy.exec(`${wpCypress} wp "seed ${seeder}"`).then((result) => {
1114
cy.log(result.stdout);
1215
});
1316
},
1417

1518
seedClean(seeder) {
16-
cy.exec(`node_modules/.bin/wp-cypress wp "seed ${seeder} --clean"`).then(
19+
cy.exec(`${wpCypress} wp "seed ${seeder} --clean"`).then(
1720
(result) => {
1821
cy.log(result.stdout);
1922
},
@@ -22,7 +25,7 @@ const commands = {
2225

2326
cleanThenSeed(seeder) {
2427
cy.exec(
25-
`node_modules/.bin/wp-cypress wp "seed ${seeder} --clean-first"`,
28+
`${wpCypress} wp "seed ${seeder} --clean-first"`,
2629
).then((result) => {
2730
cy.log(result.stdout);
2831
});
@@ -31,27 +34,27 @@ const commands = {
3134
resetWP(version = false) {
3235
const wpVersion = version || (Cypress.wp || {}).version || false;
3336
cy.log('WP Cypress: performing full teardown...');
34-
cy.exec(`node_modules/.bin/wp-cypress soft-reset ${wpVersion ? `--version='${wpVersion}'` : ''}`);
37+
cy.exec(`${wpCypress} soft-reset ${wpVersion ? `--version="${wpVersion}"` : ''}`);
3538
},
3639

3740
installTheme(name) {
38-
cy.exec(`node_modules/.bin/wp-cypress wp "theme install ${name}"`);
41+
cy.exec(`${wpCypress} wp "theme install ${name}"`);
3942
},
4043

4144
activateTheme(name) {
42-
cy.exec(`node_modules/.bin/wp-cypress wp "theme activate ${name}"`);
45+
cy.exec(`${wpCypress} wp "theme activate ${name}"`);
4346
},
4447

4548
installPlugin(name) {
46-
cy.exec(`node_modules/.bin/wp-cypress wp "plugin install ${name}"`);
49+
cy.exec(`${wpCypress} wp "plugin install ${name}"`);
4750
},
4851

4952
activatePlugin(name) {
50-
cy.exec(`node_modules/.bin/wp-cypress wp "plugin activate ${name}"`);
53+
cy.exec(`${wpCypress} wp "plugin activate ${name}"`);
5154
},
5255

5356
deactivatePlugin(name) {
54-
cy.exec(`node_modules/.bin/wp-cypress wp "plugin deactivate ${name}"`);
57+
cy.exec(`${wpCypress} wp "plugin deactivate ${name}"`);
5558
},
5659

5760
visitAdmin(options = {}) {
@@ -68,7 +71,7 @@ const commands = {
6871

6972
switchUser(user = 'admin', password = null) {
7073
if (password) {
71-
cy.exec('node_modules/.bin/wp-cypress wp "wp-cypress-set-user --logout"').then(() => {
74+
cy.exec(`${wpCypress} wp "wp-cypress-set-user --logout"`).then(() => {
7275
cy.clearCookies();
7376
cy.visit('/wp-login.php?loggedout=true');
7477

@@ -84,12 +87,12 @@ const commands = {
8487
cy.get('#wp-submit').click();
8588
});
8689
} else {
87-
cy.exec(`node_modules/.bin/wp-cypress wp "wp-cypress-set-user ${user}"`);
90+
cy.exec(`${wpCypress} wp "wp-cypress-set-user ${user}"`);
8891
}
8992
},
9093

9194
logout() {
92-
cy.exec('node_modules/.bin/wp-cypress wp "wp-cypress-set-user --logout"').then(() => {
95+
cy.exec(`${wpCypress} wp "wp-cypress-set-user --logout"`).then(() => {
9396
cy.clearCookies();
9497
cy.visit('/wp-login.php?loggedout=true');
9598
});

lib/modules/exec.js

+19-9
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,22 @@
11
const shell = require('shelljs');
22

3-
const exec = (cmd, logFile) => new Promise((resolve) => {
4-
const child = shell.exec(cmd, {
5-
async: true,
6-
silent: true,
7-
}, (code, stdout, stderr) => {
8-
resolve({ code, stdout, stderr });
9-
});
3+
const exec = (cmd, logFile, stdin) => new Promise((resolve) => {
4+
let child;
5+
if (stdin) {
6+
child = new shell.ShellString(stdin).exec(cmd, {
7+
async: true,
8+
silent: true,
9+
}, (code, stdout, stderr) => {
10+
resolve({ code, stdout, stderr });
11+
});
12+
} else {
13+
child = shell.exec(cmd, {
14+
async: true,
15+
silent: true,
16+
}, (code, stdout, stderr) => {
17+
resolve({ code, stdout, stderr });
18+
});
19+
}
1020

1121
if (!logFile) {
1222
return;
@@ -27,6 +37,6 @@ const exec = (cmd, logFile) => new Promise((resolve) => {
2737

2838
module.exports = {
2939
exec,
30-
cli: (command, logFile) => exec(`docker-compose exec -T wp ${command}`, logFile),
31-
wpcli: (command, logFile) => exec(`docker-compose exec -T wp wp --allow-root ${command}`, logFile),
40+
cli: (command, logFile, stdin) => exec(`docker-compose exec -T wp ${command}`, logFile, stdin),
41+
wpcli: (command, logFile, stdin) => exec(`docker-compose exec -T wp wp --allow-root ${command}`, logFile, stdin),
3242
};

0 commit comments

Comments
 (0)