Skip to content

Commit

Permalink
Merge pull request #13426 from backstage/freben/fix-lint-errors
Browse files Browse the repository at this point in the history
Fix linting errors after #13392
  • Loading branch information
freben committed Aug 30, 2022
2 parents 3716ae3 + aaab1e3 commit 64a3597
Show file tree
Hide file tree
Showing 151 changed files with 837 additions and 786 deletions.
3 changes: 3 additions & 0 deletions .changeset/renovate-4f0c2e3.md
Expand Up @@ -8,3 +8,6 @@ Note that this major update to the Jest plugin contains some breaking changes.
This means that some of your tests may start seeing some new lint errors. [Read
about them
here](https://github.com/jest-community/eslint-plugin-jest/blob/main/CHANGELOG.md#2700-2022-08-28).

These are mostly possible to fix automatically. You can try to run `yarn backstage-cli repo lint --fix` in your repo root to have most or all of them
corrected.
4 changes: 2 additions & 2 deletions packages/backend-common/src/cache/CacheManager.test.ts
Expand Up @@ -65,7 +65,7 @@ describe('CacheManager', () => {
const config = new ConfigReader({ backend: {} });
expect(() => {
CacheManager.fromConfig(config);
}).not.toThrowError();
}).not.toThrow();
});

it('throws on unknown cache store', () => {
Expand All @@ -74,7 +74,7 @@ describe('CacheManager', () => {
});
expect(() => {
CacheManager.fromConfig(config);
}).toThrowError();
}).toThrow();
});
});

Expand Down
72 changes: 36 additions & 36 deletions packages/backend-common/src/context/AbortContext.test.ts
Expand Up @@ -37,12 +37,12 @@ describe('AbortContext', () => {

expect(child.abortSignal.aborted).toBe(false);
expect(Math.abs(+child.deadline! - deadline)).toBeLessThan(50);
expect(childListener).toBeCalledTimes(0);
expect(childListener).toHaveBeenCalledTimes(0);

jest.advanceTimersByTime(timeout + 1);

expect(child.abortSignal.aborted).toBe(true);
expect(childListener).toBeCalledTimes(1);
expect(childListener).toHaveBeenCalledTimes(1);
});

it('results in minimum deadline when parent triggers sooner', async () => {
Expand All @@ -66,15 +66,15 @@ describe('AbortContext', () => {
expect(child.abortSignal.aborted).toBe(false);
expect(Math.abs(+parent.deadline! - parentDeadline)).toBeLessThan(50);
expect(Math.abs(+child.deadline! - childDeadline)).toBeLessThan(50);
expect(parentListener).toBeCalledTimes(0);
expect(childListener).toBeCalledTimes(0);
expect(parentListener).toHaveBeenCalledTimes(0);
expect(childListener).toHaveBeenCalledTimes(0);

jest.advanceTimersByTime(parentTimeout + 1);

expect(parent.abortSignal.aborted).toBe(true);
expect(child.abortSignal.aborted).toBe(true);
expect(parentListener).toBeCalledTimes(1);
expect(childListener).toBeCalledTimes(1);
expect(parentListener).toHaveBeenCalledTimes(1);
expect(childListener).toHaveBeenCalledTimes(1);
});

it('results in minimum deadline when child triggers sooner', async () => {
Expand All @@ -98,22 +98,22 @@ describe('AbortContext', () => {
expect(child.abortSignal.aborted).toBe(false);
expect(Math.abs(+parent.deadline! - parentDeadline)).toBeLessThan(50);
expect(Math.abs(+child.deadline! - childDeadline)).toBeLessThan(50);
expect(parentListener).toBeCalledTimes(0);
expect(childListener).toBeCalledTimes(0);
expect(parentListener).toHaveBeenCalledTimes(0);
expect(childListener).toHaveBeenCalledTimes(0);

jest.advanceTimersByTime(childTimeout + 1);

expect(parent.abortSignal.aborted).toBe(false);
expect(child.abortSignal.aborted).toBe(true);
expect(parentListener).toBeCalledTimes(0);
expect(childListener).toBeCalledTimes(1);
expect(parentListener).toHaveBeenCalledTimes(0);
expect(childListener).toHaveBeenCalledTimes(1);

jest.advanceTimersByTime(parentTimeout - childTimeout + 1);

expect(parent.abortSignal.aborted).toBe(true);
expect(child.abortSignal.aborted).toBe(true);
expect(parentListener).toBeCalledTimes(1);
expect(childListener).toBeCalledTimes(1);
expect(parentListener).toHaveBeenCalledTimes(1);
expect(childListener).toHaveBeenCalledTimes(1);
});

it('child carries over parent signal state if parent was already aborted and had no deadline', async () => {
Expand All @@ -133,13 +133,13 @@ describe('AbortContext', () => {
child.abortSignal.addEventListener('abort', childListener);

expect(child.abortSignal.aborted).toBe(true);
expect(childListener).toBeCalledTimes(0);
expect(childListener).toHaveBeenCalledTimes(0);
expect(Math.abs(+child.deadline! - childDeadline)).toBeLessThan(50);

jest.advanceTimersByTime(childTimeout + 1);

expect(child.abortSignal.aborted).toBe(true);
expect(childListener).toBeCalledTimes(0); // still
expect(childListener).toHaveBeenCalledTimes(0); // still
});

it('child carries over parent signal state if parent was already aborted and had a deadline', async () => {
Expand Down Expand Up @@ -175,15 +175,15 @@ describe('AbortContext', () => {

expect(parent.abortSignal.aborted).toBe(false);
expect(child.abortSignal.aborted).toBe(false);
expect(parentListener).toBeCalledTimes(0);
expect(childListener).toBeCalledTimes(0);
expect(parentListener).toHaveBeenCalledTimes(0);
expect(childListener).toHaveBeenCalledTimes(0);

parentController.abort();

expect(parent.abortSignal.aborted).toBe(true);
expect(child.abortSignal.aborted).toBe(true);
expect(parentListener).toBeCalledTimes(1);
expect(childListener).toBeCalledTimes(1);
expect(parentListener).toHaveBeenCalledTimes(1);
expect(childListener).toHaveBeenCalledTimes(1);
});

it('does not signal parent when child is aborted', async () => {
Expand All @@ -201,15 +201,15 @@ describe('AbortContext', () => {

expect(parent.abortSignal.aborted).toBe(false);
expect(child.abortSignal.aborted).toBe(false);
expect(parentListener).toBeCalledTimes(0);
expect(childListener).toBeCalledTimes(0);
expect(parentListener).toHaveBeenCalledTimes(0);
expect(childListener).toHaveBeenCalledTimes(0);

childController.abort();

expect(parent.abortSignal.aborted).toBe(false);
expect(child.abortSignal.aborted).toBe(true);
expect(parentListener).toBeCalledTimes(0);
expect(childListener).toBeCalledTimes(1);
expect(parentListener).toHaveBeenCalledTimes(0);
expect(childListener).toHaveBeenCalledTimes(1);
});

it('child carries over parent signal state if parent was already aborted', async () => {
Expand All @@ -227,13 +227,13 @@ describe('AbortContext', () => {

expect(parent.abortSignal.aborted).toBe(true);
expect(child.abortSignal.aborted).toBe(true);
expect(childListener).toBeCalledTimes(0);
expect(childListener).toHaveBeenCalledTimes(0);

childController.abort();

expect(parent.abortSignal.aborted).toBe(true);
expect(child.abortSignal.aborted).toBe(true);
expect(childListener).toBeCalledTimes(0);
expect(childListener).toHaveBeenCalledTimes(0);
});

it('child carries over given signal state if it was already aborted', async () => {
Expand All @@ -247,7 +247,7 @@ describe('AbortContext', () => {
child.abortSignal.addEventListener('abort', childListener);

expect(child.abortSignal.aborted).toBe(true);
expect(childListener).toBeCalledTimes(0);
expect(childListener).toHaveBeenCalledTimes(0);
});
});

Expand All @@ -267,15 +267,15 @@ describe('AbortContext', () => {

expect(parent.abortSignal.aborted).toBe(false);
expect(child.abortSignal.aborted).toBe(false);
expect(parentListener).toBeCalledTimes(0);
expect(childListener).toBeCalledTimes(0);
expect(parentListener).toHaveBeenCalledTimes(0);
expect(childListener).toHaveBeenCalledTimes(0);

parentController.abort();

expect(parent.abortSignal.aborted).toBe(true);
expect(child.abortSignal.aborted).toBe(true);
expect(parentListener).toBeCalledTimes(1);
expect(childListener).toBeCalledTimes(1);
expect(parentListener).toHaveBeenCalledTimes(1);
expect(childListener).toHaveBeenCalledTimes(1);
});

it('does not signal parent when child is aborted', async () => {
Expand All @@ -293,15 +293,15 @@ describe('AbortContext', () => {

expect(parent.abortSignal.aborted).toBe(false);
expect(child.abortSignal.aborted).toBe(false);
expect(parentListener).toBeCalledTimes(0);
expect(childListener).toBeCalledTimes(0);
expect(parentListener).toHaveBeenCalledTimes(0);
expect(childListener).toHaveBeenCalledTimes(0);

childController.abort();

expect(parent.abortSignal.aborted).toBe(false);
expect(child.abortSignal.aborted).toBe(true);
expect(parentListener).toBeCalledTimes(0);
expect(childListener).toBeCalledTimes(1);
expect(parentListener).toHaveBeenCalledTimes(0);
expect(childListener).toHaveBeenCalledTimes(1);
});

it('child carries over parent signal state if parent was already aborted', async () => {
Expand All @@ -319,13 +319,13 @@ describe('AbortContext', () => {

expect(parent.abortSignal.aborted).toBe(true);
expect(child.abortSignal.aborted).toBe(true);
expect(childListener).toBeCalledTimes(0);
expect(childListener).toHaveBeenCalledTimes(0);

childController.abort();

expect(parent.abortSignal.aborted).toBe(true);
expect(child.abortSignal.aborted).toBe(true);
expect(childListener).toBeCalledTimes(0);
expect(childListener).toHaveBeenCalledTimes(0);
});

it('child carries over given signal state if it was already aborted', async () => {
Expand All @@ -339,7 +339,7 @@ describe('AbortContext', () => {
child.abortSignal.addEventListener('abort', childListener);

expect(child.abortSignal.aborted).toBe(true);
expect(childListener).toBeCalledTimes(0);
expect(childListener).toHaveBeenCalledTimes(0);
});
});
});
6 changes: 3 additions & 3 deletions packages/backend-common/src/database/connection.test.ts
Expand Up @@ -110,7 +110,7 @@ describe('database connection', () => {
connection: '',
}),
),
).toThrowError();
).toThrow();
});

it('throws an error without a connection', () => {
Expand All @@ -120,7 +120,7 @@ describe('database connection', () => {
client: 'pg',
}),
),
).toThrowError();
).toThrow();
});
});

Expand All @@ -147,7 +147,7 @@ describe('database connection', () => {
});

it('throws an error for unknown connection', () => {
expect(() => createNameOverride('unknown', 'testname')).toThrowError();
expect(() => createNameOverride('unknown', 'testname')).toThrow();
});
});

Expand Down
Expand Up @@ -194,7 +194,7 @@ describe('postgres', () => {
'postgresql://postgres:pass@localhost:5432/dbname?sslrootcert=/path/to/file',
),
),
).toThrowError(/no such file or directory/);
).toThrow(/no such file or directory/);
});
});

Expand Down
Expand Up @@ -551,7 +551,7 @@ describe('GithubUrlReader', () => {
credentialsProvider: mockCredentialsProvider,
},
);
}).toThrowError('must configure an explicit apiBaseUrl');
}).toThrow('must configure an explicit apiBaseUrl');
});
});

Expand Down
Expand Up @@ -127,7 +127,7 @@ describe('GcsUrlReader', () => {

it('throws if search url looks truly glob-y', async () => {
const glob = 'https://storage.cloud.google.com/bucket/**/path*';
await expect(() => reader.search(glob)).rejects.toThrowError(
await expect(() => reader.search(glob)).rejects.toThrow(
'GcsUrlReader only supports prefix-based searches',
);
});
Expand Down
Expand Up @@ -55,7 +55,7 @@ describe('ReadUrlResponseFactory', () => {
it('buffer cannot be called after stream is called', async () => {
const response = await ReadUrlResponseFactory.fromReadable(readable);
response.stream!();
expect(() => response.buffer()).toThrowError(ConflictError);
expect(() => response.buffer()).toThrow(ConflictError);
});

it('stream returns expected data', async () => {
Expand All @@ -68,7 +68,7 @@ describe('ReadUrlResponseFactory', () => {
it('stream cannot be called after buffer is called', async () => {
const response = await ReadUrlResponseFactory.fromReadable(readable);
response.buffer();
expect(() => response.stream!()).toThrowError(ConflictError);
expect(() => response.stream!()).toThrow(ConflictError);
});
});

Expand Down
Expand Up @@ -64,7 +64,7 @@ describe('UrlReaderPredicateMux', () => {
it('throws an error if no predicate matches', async () => {
const mux = new UrlReaderPredicateMux(getVoidLogger());

await expect(mux.readUrl('http://foo/1')).rejects.toThrowError(
await expect(mux.readUrl('http://foo/1')).rejects.toThrow(
/^Reading from 'http:\/\/foo\/1' is not allowed. You may/,
);

Expand All @@ -80,7 +80,7 @@ describe('UrlReaderPredicateMux', () => {

await expect(mux.readUrl('http://foo/1')).resolves.toBeUndefined();

await expect(mux.readUrl('http://bar/1')).rejects.toThrowError(
await expect(mux.readUrl('http://bar/1')).rejects.toThrow(
/^Reading from 'http:\/\/bar\/1' is not allowed. You may/,
);
});
Expand Down
12 changes: 6 additions & 6 deletions packages/backend-common/src/tokens/ServerTokenManager.test.ts
Expand Up @@ -66,9 +66,9 @@ describe('ServerTokenManager', () => {
const tokenManager = ServerTokenManager.fromConfig(configWithSecret, {
logger,
});
await expect(
tokenManager.authenticate('random-string'),
).rejects.toThrowError(/invalid server token/i);
await expect(tokenManager.authenticate('random-string')).rejects.toThrow(
/invalid server token/i,
);
});

it('should validate server tokens created by a different instance using the same secret', async () => {
Expand Down Expand Up @@ -129,7 +129,7 @@ describe('ServerTokenManager', () => {

const { token } = await tokenManager1.getToken();

await expect(tokenManager2.authenticate(token)).rejects.toThrowError(
await expect(tokenManager2.authenticate(token)).rejects.toThrow(
/invalid server token/i,
);
});
Expand All @@ -145,7 +145,7 @@ describe('ServerTokenManager', () => {

const { token } = await noopTokenManager.getToken();

await expect(tokenManager.authenticate(token)).rejects.toThrowError(
await expect(tokenManager.authenticate(token)).rejects.toThrow(
/invalid server token/i,
);
});
Expand All @@ -164,7 +164,7 @@ describe('ServerTokenManager', () => {

const { token } = await tokenManager2.getToken();

await expect(tokenManager1.authenticate(token)).rejects.toThrowError(
await expect(tokenManager1.authenticate(token)).rejects.toThrow(
/invalid server token/i,
);
});
Expand Down

0 comments on commit 64a3597

Please sign in to comment.