Skip to content

Commit

Permalink
Blueprints: add unit tests to the mkdir step (#1029)
Browse files Browse the repository at this point in the history
Adds tests to the mkdir step.

Tests directory creation minding idempotence and recursivity. 

Part of the #756 effort.

---------

Co-authored-by: Adam Zielinski <adam@adamziel.com>
  • Loading branch information
reimic and adamziel authored Mar 4, 2024
1 parent 8b74852 commit daeef68
Showing 1 changed file with 42 additions and 0 deletions.
42 changes: 42 additions & 0 deletions packages/playground/blueprints/src/lib/steps/mkdir.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import { NodePHP } from '@php-wasm/node';
import { RecommendedPHPVersion } from '@wp-playground/wordpress';
import { mkdir } from './mkdir';

describe('Blueprint step mkdir', () => {
let php: NodePHP;
beforeEach(async () => {
php = await NodePHP.load(RecommendedPHPVersion);
});

it('should create a directory', async () => {
const directoryToCreate = '/php/dir';
await mkdir(php, {
path: directoryToCreate,
});
expect(php.isDir(directoryToCreate)).toBe(true);
});

it('should create a directory recursively', async () => {
const directoryToCreate = '/php/dir/subDir';
await mkdir(php, {
path: directoryToCreate,
});
expect(php.isDir(directoryToCreate)).toBe(true);
});

it('should do nothing when asked to create a directory that is allready there', async () => {
const existingDirectory = '/php/dir';
php.mkdir(existingDirectory);

const existingFile = '/php/dir/index.php';
php.writeFile(existingFile, `<?php echo 'Hello World';`);

mkdir(php, {
path: existingDirectory,
});

expect(php.readFileAsText(existingFile)).toBe(
`<?php echo 'Hello World';`
);
});
});

0 comments on commit daeef68

Please sign in to comment.