Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Blueprints: add unit tests to the rmdir step #1021

Open
wants to merge 3 commits into
base: trunk
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
57 changes: 57 additions & 0 deletions packages/playground/blueprints/src/lib/steps/rmdir.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import { NodePHP } from '@php-wasm/node';
import { RecommendedPHPVersion } from '@wp-playground/wordpress';
import { rmdir } from './rmdir';

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

it('should remove a directory', async () => {
const directoryToRemove = '/php/dir';
php.mkdir(directoryToRemove);
await rmdir(php, {
path: directoryToRemove,
});
expect(php.fileExists(directoryToRemove)).toBe(false);
});

it('should remove a directory with a subdirectory', async () => {
const directoryToRemove = '/php/dir';
php.mkdir('/php/dir/subDir');
await rmdir(php, {
path: directoryToRemove,
});
expect(php.fileExists(directoryToRemove)).toBe(false);
});

it('should remove a directory with a file', async () => {
const directoryToRemove = '/php/dir';
php.mkdir(directoryToRemove);
php.writeFile(`/php/dir/file.php`, `<?php echo 'Hello World';`);
await rmdir(php, {
path: directoryToRemove,
});
expect(php.fileExists(directoryToRemove)).toBe(false);
});

it('should fail when the directory does not exist', async () => {
await expect(
rmdir(php, {
path: '/php/dir',
})
).rejects.toThrow(/There is no such file or directory/);
});

it('should fail when the directory is a file', async () => {
php.mkdir('/php/dir');
php.writeFile(`/php/dir/index.php`, `<?php echo 'Hello World';`);
await expect(
rmdir(php, {
path: '/php/dir/index.php',
})
).rejects.toThrow(/Not a directory or a symbolic link to a directory./);
});
});