Skip to content

Commit

Permalink
Use a tmp directory for WP-CLI tests
Browse files Browse the repository at this point in the history
  • Loading branch information
danielbachhuber committed May 25, 2023
1 parent a241c2d commit 5e8e97c
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 3 deletions.
3 changes: 2 additions & 1 deletion packages/wp-now/src/get-wp-cli-path.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import path from 'path';
import getWpNowPath from './get-wp-now-path';
import getWpCliTmpPath from './get-wp-cli-tmp-path';

/**
* The path for wp-cli phar file within the WP Now folder.
Expand All @@ -8,5 +9,5 @@ export default function getWpCliPath() {
if (process.env.NODE_ENV !== 'test') {
return path.join(getWpNowPath(), 'wp-cli.phar');
}
return path.resolve('./wp-cli.phar');
return getWpCliTmpPath();
}
11 changes: 11 additions & 0 deletions packages/wp-now/src/get-wp-cli-tmp-path.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import path from 'path';
import os from 'os';

/**
* The full path to the hidden WP-CLI folder in the user's tmp directory.
*/
export default function getWpCliTmpPath() {
const tmpDirectory = os.tmpdir();

return path.join(tmpDirectory, `wp-now-tests-wp-cli-hidden-folder`);
}
4 changes: 2 additions & 2 deletions packages/wp-now/src/tests/wp-now.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ import {
import os from 'os';
import crypto from 'crypto';
import getWpNowTmpPath from '../get-wp-now-tmp-path';
import getWpCliTmpPath from '../get-wp-cli-tmp-path';
import { executeWPCli } from '../execute-wp-cli';
import getWpCliPath from '../get-wp-cli-path';

const exampleDir = __dirname + '/mode-examples';

Expand Down Expand Up @@ -539,7 +539,7 @@ describe('wp-cli command', () => {
});

afterAll(() => {
fs.removeSync(getWpCliPath());
fs.removeSync(getWpCliTmpPath());
});

/**
Expand Down

0 comments on commit 5e8e97c

Please sign in to comment.