-
Notifications
You must be signed in to change notification settings - Fork 271
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Blueprints: add unit tests to the mkdir step (#1029)
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
Showing
1 changed file
with
42 additions
and
0 deletions.
There are no files selected for viewing
42 changes: 42 additions & 0 deletions
42
packages/playground/blueprints/src/lib/steps/mkdir.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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';` | ||
); | ||
}); | ||
}); |