From e434e77f268342135f4cb0dfa7f3cc412500163a Mon Sep 17 00:00:00 2001 From: Michael Reichardt <30837295+reimic@users.noreply.github.com> Date: Sun, 11 Feb 2024 11:24:34 +0000 Subject: [PATCH 1/2] add unit tests to the rmdir step --- .../blueprints/src/lib/steps/rmdir.spec.ts | 60 +++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 packages/playground/blueprints/src/lib/steps/rmdir.spec.ts diff --git a/packages/playground/blueprints/src/lib/steps/rmdir.spec.ts b/packages/playground/blueprints/src/lib/steps/rmdir.spec.ts new file mode 100644 index 0000000000..ae7cb78815 --- /dev/null +++ b/packages/playground/blueprints/src/lib/steps/rmdir.spec.ts @@ -0,0 +1,60 @@ +import { NodePHP } from '@php-wasm/node'; +import { RecommendedPHPVersion } from '@wp-playground/wordpress'; +import { rmdir } from './rmdir'; + +const docroot = '/php'; +describe('Blueprint step rmdir()', () => { + let php: NodePHP; + beforeEach(async () => { + php = await NodePHP.load(RecommendedPHPVersion); + php.mkdir(docroot); + }); + + it('should remove a directory', async () => { + php.mkdir(`/${docroot}/dir1`); + await rmdir(php, { + path: `/${docroot}/dir1`, + }); + expect(php.fileExists(`/${docroot}/dir1`)).toBe(false); + }); + + it('should remove a directory with a subdirectory', async () => { + php.mkdir(`/${docroot}/dir1`); + php.mkdir(`/${docroot}/dir1/dir11`); + await rmdir(php, { + path: `/${docroot}/dir1`, + }); + expect(php.fileExists(`/${docroot}/dir1/dir11`)).toBe(false); + expect(php.fileExists(`/${docroot}/dir1`)).toBe(false); + }); + + it('should remove a directory with a file', async () => { + php.mkdir(`/${docroot}/dir1`); + php.writeFile( + `/${docroot}/dir1/index.php`, + ` { + await expect( + rmdir(php, { + path: `/${docroot}/dir1`, + }) + ).rejects.toThrow(/There is no such file or directory/); + }); + + it('should fail when the directory is a file', async () => { + php.writeFile(`/${docroot}/index.php`, ` Date: Sat, 2 Mar 2024 10:46:30 +0000 Subject: [PATCH 2/2] apply changes after review --- .../blueprints/src/lib/steps/rmdir.spec.ts | 39 +++++++++---------- 1 file changed, 18 insertions(+), 21 deletions(-) diff --git a/packages/playground/blueprints/src/lib/steps/rmdir.spec.ts b/packages/playground/blueprints/src/lib/steps/rmdir.spec.ts index ae7cb78815..f707fa9c55 100644 --- a/packages/playground/blueprints/src/lib/steps/rmdir.spec.ts +++ b/packages/playground/blueprints/src/lib/steps/rmdir.spec.ts @@ -2,58 +2,55 @@ import { NodePHP } from '@php-wasm/node'; import { RecommendedPHPVersion } from '@wp-playground/wordpress'; import { rmdir } from './rmdir'; -const docroot = '/php'; describe('Blueprint step rmdir()', () => { let php: NodePHP; beforeEach(async () => { php = await NodePHP.load(RecommendedPHPVersion); - php.mkdir(docroot); + php.mkdir('/php'); }); it('should remove a directory', async () => { - php.mkdir(`/${docroot}/dir1`); + const directoryToRemove = '/php/dir'; + php.mkdir(directoryToRemove); await rmdir(php, { - path: `/${docroot}/dir1`, + path: directoryToRemove, }); - expect(php.fileExists(`/${docroot}/dir1`)).toBe(false); + expect(php.fileExists(directoryToRemove)).toBe(false); }); it('should remove a directory with a subdirectory', async () => { - php.mkdir(`/${docroot}/dir1`); - php.mkdir(`/${docroot}/dir1/dir11`); + const directoryToRemove = '/php/dir'; + php.mkdir('/php/dir/subDir'); await rmdir(php, { - path: `/${docroot}/dir1`, + path: directoryToRemove, }); - expect(php.fileExists(`/${docroot}/dir1/dir11`)).toBe(false); - expect(php.fileExists(`/${docroot}/dir1`)).toBe(false); + expect(php.fileExists(directoryToRemove)).toBe(false); }); it('should remove a directory with a file', async () => { - php.mkdir(`/${docroot}/dir1`); - php.writeFile( - `/${docroot}/dir1/index.php`, - ` { await expect( rmdir(php, { - path: `/${docroot}/dir1`, + path: '/php/dir', }) ).rejects.toThrow(/There is no such file or directory/); }); it('should fail when the directory is a file', async () => { - php.writeFile(`/${docroot}/index.php`, `