From f209cb55456471ad1ed29295f783322cce010766 Mon Sep 17 00:00:00 2001 From: Alan Agius Date: Thu, 27 May 2021 11:09:05 +0200 Subject: [PATCH] test(@angular-devkit/core): update host tests to not use deprecated Jasmine behaviour ``` DEPRECATION: An asynchronous before/it/after function was defined with the async keyword but also took a done callback. This is not supported and will stop working in the future. Either remove the done callback (recommended) or remove the async keyword. ``` --- .../core/src/workspace/core_spec.ts | 44 +++++-------------- .../core/src/workspace/host_spec.ts | 16 ++----- 2 files changed, 15 insertions(+), 45 deletions(-) diff --git a/packages/angular_devkit/core/src/workspace/core_spec.ts b/packages/angular_devkit/core/src/workspace/core_spec.ts index 1dc00f3eb4..932970f84c 100644 --- a/packages/angular_devkit/core/src/workspace/core_spec.ts +++ b/packages/angular_devkit/core/src/workspace/core_spec.ts @@ -19,7 +19,7 @@ import { WorkspaceDefinition } from './definitions'; import { WorkspaceHost } from './host'; describe('readWorkspace', () => { - it('attempts to read from specified file path [angular.json]', async (done) => { + it('attempts to read from specified file path [angular.json]', async () => { const requestedPath = '/path/to/workspace/angular.json'; const host: WorkspaceHost = { @@ -42,11 +42,9 @@ describe('readWorkspace', () => { }; await readWorkspace(requestedPath, host); - - done(); }); - it('attempts to read from specified file path [.angular.json]', async (done) => { + it('attempts to read from specified file path [.angular.json]', async () => { const requestedPath = '/path/to/workspace/.angular.json'; const host: WorkspaceHost = { @@ -69,11 +67,9 @@ describe('readWorkspace', () => { }; await readWorkspace(requestedPath, host); - - done(); }); - it('attempts to read from specified non-standard file path with format', async (done) => { + it('attempts to read from specified non-standard file path with format', async () => { const requestedPath = '/path/to/workspace/abc.json'; const host: WorkspaceHost = { @@ -96,11 +92,9 @@ describe('readWorkspace', () => { }; await readWorkspace(requestedPath, host, WorkspaceFormat.JSON); - - done(); }); - it('errors when reading from specified non-standard file path without format', async (done) => { + it('errors when reading from specified non-standard file path without format', async () => { const requestedPath = '/path/to/workspace/abc.json'; const host: WorkspaceHost = { @@ -128,11 +122,9 @@ describe('readWorkspace', () => { } catch (e) { expect(e.message).toContain('Unable to determine format for workspace path'); } - - done(); }); - it('errors when reading from specified file path with invalid specified format', async (done) => { + it('errors when reading from specified file path with invalid specified format', async () => { const requestedPath = '/path/to/workspace/angular.json'; const host: WorkspaceHost = { @@ -160,11 +152,9 @@ describe('readWorkspace', () => { } catch (e) { expect(e.message).toContain('Unsupported workspace format'); } - - done(); }); - it('attempts to find/read from directory path', async (done) => { + it('attempts to find/read from directory path', async () => { const requestedPath = getSystemPath(normalize('/path/to/workspace')); const expectedFile = getSystemPath(join(normalize(requestedPath), '.angular.json')); @@ -201,11 +191,9 @@ describe('readWorkspace', () => { getSystemPath(join(normalize(requestedPath), '.angular.json')), ].sort(), ); - - done(); }); - it('attempts to find/read only files for specified format from directory path', async (done) => { + it('attempts to find/read only files for specified format from directory path', async () => { const requestedPath = '/path/to/workspace'; const isFileChecks: string[] = []; @@ -246,11 +234,9 @@ describe('readWorkspace', () => { readFileChecks.sort(); expect(readFileChecks).toEqual([getSystemPath(join(normalize(requestedPath), 'angular.json'))]); - - done(); }); - it('errors when no file found from specified directory path', async (done) => { + it('errors when no file found from specified directory path', async () => { const requestedPath = '/path/to/workspace'; const host: WorkspaceHost = { @@ -280,13 +266,11 @@ describe('readWorkspace', () => { } catch (e) { expect(e.message).toContain('Unable to locate a workspace file'); } - - done(); }); }); describe('writeWorkspace', () => { - it('attempts to write to specified file path', async (done) => { + it('attempts to write to specified file path', async () => { const requestedPath = '/path/to/workspace/angular.json'; let writtenPath: string | undefined; @@ -314,11 +298,9 @@ describe('writeWorkspace', () => { await writeWorkspace({} as WorkspaceDefinition, host, requestedPath, WorkspaceFormat.JSON); expect(writtenPath).toBe(requestedPath); - - done(); }); - it('errors when writing to specified file path with invalid specified format', async (done) => { + it('errors when writing to specified file path with invalid specified format', async () => { const requestedPath = '/path/to/workspace/angular.json'; const host: WorkspaceHost = { @@ -348,11 +330,9 @@ describe('writeWorkspace', () => { } catch (e) { expect(e.message).toContain('Unsupported workspace format'); } - - done(); }); - it('errors when writing custom workspace without specified format', async (done) => { + it('errors when writing custom workspace without specified format', async () => { const requestedPath = '/path/to/workspace/angular.json'; const host: WorkspaceHost = { @@ -382,7 +362,5 @@ describe('writeWorkspace', () => { } catch (e) { expect(e.message).toContain('A format is required'); } - - done(); }); }); diff --git a/packages/angular_devkit/core/src/workspace/host_spec.ts b/packages/angular_devkit/core/src/workspace/host_spec.ts index 83abe4fef5..2985e85bf3 100644 --- a/packages/angular_devkit/core/src/workspace/host_spec.ts +++ b/packages/angular_devkit/core/src/workspace/host_spec.ts @@ -21,18 +21,16 @@ describe('createWorkspaceHost', () => { workspaceHost = createWorkspaceHost(testHost); }); - it('supports isFile', async (done) => { + it('supports isFile', async () => { expect(await workspaceHost.isFile('abc.txt')).toBeTruthy(); expect(await workspaceHost.isFile('foo/bar.json')).toBeTruthy(); expect(await workspaceHost.isFile('foo\\bar.json')).toBeTruthy(); expect(await workspaceHost.isFile('foo')).toBeFalsy(); expect(await workspaceHost.isFile('not.there')).toBeFalsy(); - - done(); }); - it('supports isDirectory', async (done) => { + it('supports isDirectory', async () => { expect(await workspaceHost.isDirectory('foo')).toBeTruthy(); expect(await workspaceHost.isDirectory('foo/')).toBeTruthy(); expect(await workspaceHost.isDirectory('foo\\')).toBeTruthy(); @@ -40,22 +38,16 @@ describe('createWorkspaceHost', () => { expect(await workspaceHost.isDirectory('abc.txt')).toBeFalsy(); expect(await workspaceHost.isDirectory('foo/bar.json')).toBeFalsy(); expect(await workspaceHost.isDirectory('not.there')).toBeFalsy(); - - done(); }); - it('supports readFile', async (done) => { + it('supports readFile', async () => { expect(await workspaceHost.readFile('abc.txt')).toBe('abcdefg'); - - done(); }); - it('supports writeFile', async (done) => { + it('supports writeFile', async () => { await workspaceHost.writeFile('newfile', 'baz'); expect(testHost.files.sort() as string[]).toEqual(['/abc.txt', '/foo/bar.json', '/newfile']); expect(testHost.$read('newfile')).toBe('baz'); - - done(); }); });