Making progress on getting the eslint-jest plugin working.

This commit is contained in:
Sam Rose 2024-03-19 10:46:59 +00:00
parent 1f63f0bddf
commit 7a63dc9830
No known key found for this signature in database
12 changed files with 35 additions and 87 deletions

View File

@ -34,6 +34,7 @@
},
{
"files": ["**/*.ts"],
"excludedFiles": ["qa-core/**"],
"parser": "@typescript-eslint/parser",
"extends": ["eslint:recommended"],
"rules": {
@ -48,6 +49,7 @@
},
{
"files": ["**/*.spec.ts"],
"excludedFiles": ["qa-core/**"],
"parser": "@typescript-eslint/parser",
"plugins": ["jest"],
"extends": ["eslint:recommended", "plugin:jest/recommended"],
@ -63,7 +65,13 @@
"no-prototype-builtins": "off",
"local-rules/no-test-com": "error",
"local-rules/email-domain-example-com": "error",
"no-console": "warn"
"no-console": "warn",
// We have a lot of tests that don't have assertions, they use our test
// API client that does the assertions for them
"jest/expect-expect": "off",
// We do this in some tests where the behaviour of internal tables
// differs to external, but the API is broadly the same
"jest/no-conditional-expect": "off"
}
},
{

View File

@ -4,10 +4,10 @@ set -e
if [[ -n $CI ]]
then
# --runInBand performs better in ci where resources are limited
echo "jest --coverage --runInBand --forceExit"
jest --coverage --runInBand --forceExit
echo "jest --coverage --runInBand --forceExit $@"
jest --coverage --runInBand --forceExit $@
else
# --maxWorkers performs better in development
echo "jest --coverage --detectOpenHandles"
jest --coverage --detectOpenHandles
echo "jest --coverage --forceExit --detectOpenHandles $@"
jest --coverage --forceExit --detectOpenHandles $@
fi

View File

@ -147,17 +147,6 @@ describe("redis", () => {
expect(results).toEqual([1, 2, 3, 4, 5])
})
it("can increment on a new key", async () => {
const key1 = structures.uuid()
const key2 = structures.uuid()
const result1 = await redis.increment(key1)
expect(result1).toBe(1)
const result2 = await redis.increment(key2)
expect(result2).toBe(1)
})
it("can increment multiple times in parallel", async () => {
const key = structures.uuid()
const results = await Promise.all(

View File

@ -25,8 +25,8 @@ describe("/applications/:appId/import", () => {
.expect(200)
const appPackage = await config.api.application.get(appId!)
expect(appPackage.navigation?.links?.length).toBe(2)
expect(expect(appPackage.navigation?.links?.[0].url).toBe("/blank"))
expect(expect(appPackage.navigation?.links?.[1].url).toBe("/derp"))
expect(appPackage.navigation?.links?.[0].url).toBe("/blank")
expect(appPackage.navigation?.links?.[1].url).toBe("/derp")
const screens = await config.api.screen.list()
expect(screens.length).toBe(2)
expect(screens[0].routing.route).toBe("/derp")

View File

@ -30,7 +30,9 @@ describe("/applications", () => {
beforeEach(async () => {
app = await config.api.application.create({ name: utils.newid() })
const deployment = await config.api.application.publish(app.appId)
expect(deployment.status).toBe("SUCCESS")
if (deployment.status !== "SUCCESS") {
throw new Error("Failed to publish app")
}
jest.clearAllMocks()
})

View File

@ -103,7 +103,7 @@ describe("MySQL Integration", () => {
)
})
it.skip("parses strings matching a valid date format", async () => {
it("parses strings matching a valid date format", async () => {
const sql = "select * from users;"
await config.integration.read({
sql,

View File

@ -22,11 +22,6 @@ describe("Oracle Integration", () => {
config = new TestConfiguration()
})
afterEach(() => {
expect(oracledb.closeMock).toHaveBeenCalled()
expect(oracledb.closeMock).toHaveBeenCalledTimes(1)
})
it("calls the create method with the correct params", async () => {
const sql = "insert into users (name, age) values ('Joe', 123);"
await config.integration.create({
@ -34,6 +29,7 @@ describe("Oracle Integration", () => {
})
expect(oracledb.executeMock).toHaveBeenCalledWith(sql, [], options)
expect(oracledb.executeMock).toHaveBeenCalledTimes(1)
expect(oracledb.closeMock).toHaveBeenCalledTimes(1)
})
it("calls the read method with the correct params", async () => {
@ -43,6 +39,7 @@ describe("Oracle Integration", () => {
})
expect(oracledb.executeMock).toHaveBeenCalledWith(sql, [], options)
expect(oracledb.executeMock).toHaveBeenCalledTimes(1)
expect(oracledb.closeMock).toHaveBeenCalledTimes(1)
})
it("calls the update method with the correct params", async () => {
@ -52,6 +49,7 @@ describe("Oracle Integration", () => {
})
expect(oracledb.executeMock).toHaveBeenCalledWith(sql, [], options)
expect(oracledb.executeMock).toHaveBeenCalledTimes(1)
expect(oracledb.closeMock).toHaveBeenCalledTimes(1)
})
it("calls the delete method with the correct params", async () => {
@ -61,6 +59,7 @@ describe("Oracle Integration", () => {
})
expect(oracledb.executeMock).toHaveBeenCalledWith(sql, [], options)
expect(oracledb.executeMock).toHaveBeenCalledTimes(1)
expect(oracledb.closeMock).toHaveBeenCalledTimes(1)
})
describe("no rows returned", () => {
@ -75,6 +74,7 @@ describe("Oracle Integration", () => {
})
expect(response).toEqual([{ created: true }])
expect(oracledb.executeMock).toHaveBeenCalledTimes(1)
expect(oracledb.closeMock).toHaveBeenCalledTimes(1)
})
it("returns the correct response when the update response has no rows", async () => {
@ -84,6 +84,7 @@ describe("Oracle Integration", () => {
})
expect(response).toEqual([{ updated: true }])
expect(oracledb.executeMock).toHaveBeenCalledTimes(1)
expect(oracledb.closeMock).toHaveBeenCalledTimes(1)
})
it("returns the correct response when the delete response has no rows", async () => {
@ -93,6 +94,7 @@ describe("Oracle Integration", () => {
})
expect(response).toEqual([{ deleted: true }])
expect(oracledb.executeMock).toHaveBeenCalledTimes(1)
expect(oracledb.closeMock).toHaveBeenCalledTimes(1)
})
})
})

View File

@ -418,9 +418,9 @@ describe("REST Integration", () => {
})
// @ts-ignore
const sentData = fetch.mock.calls[0][1].body
expect(sentData.has(pageParam))
expect(sentData.has(pageParam)).toEqual(true)
expect(sentData.get(pageParam)).toEqual(pageValue.toString())
expect(sentData.has(sizeParam))
expect(sentData.has(pageParam)).toEqual(true)
expect(sentData.get(sizeParam)).toEqual(sizeValue.toString())
})
})
@ -551,9 +551,9 @@ describe("REST Integration", () => {
})
// @ts-ignore
const sentData = fetch.mock.calls[0][1].body
expect(sentData.has(pageParam))
expect(sentData.has(pageParam)).toEqual(true)
expect(sentData.get(pageParam)).toEqual(pageValue.toString())
expect(sentData.has(sizeParam))
expect(sentData.has(pageParam)).toEqual(true)
expect(sentData.get(sizeParam)).toEqual(sizeValue.toString())
expect(res.pagination.cursor).toEqual(123)
})

View File

@ -342,25 +342,6 @@ describe("SQL query builder", () => {
})
})
it("should use greater than when only low range specified", () => {
const date = new Date()
const query = sql._query(
generateReadJson({
filters: {
range: {
property: {
low: date,
},
},
},
})
)
expect(query).toEqual({
bindings: [date, limit],
sql: `select * from (select * from "${TABLE_NAME}" where "${TABLE_NAME}"."property" > $1 limit $2) as "${TABLE_NAME}"`,
})
})
it("should use AND like expression for MS-SQL when filter is contains", () => {
const query = new Sql(SqlClient.MS_SQL, 10)._query(
generateReadJson({

View File

@ -294,7 +294,7 @@ describe("Captures of real examples", () => {
type: "datasource",
isSQL: false,
})
)
).toEqual(true)
})
it("should disable when no fields", () => {

View File

@ -360,7 +360,10 @@ describe("/api/global/auth", () => {
const res = await config.api.configs.OIDCCallback(configId, preAuthRes)
expect(events.auth.login).toHaveBeenCalledWith("oidc", "oauth@example.com")
expect(events.auth.login).toHaveBeenCalledWith(
"oidc",
"oauth@example.com"
)
expect(events.auth.login).toHaveBeenCalledTimes(1)
expect(res.status).toBe(302)
const location: string = res.get("location")
@ -368,13 +371,5 @@ describe("/api/global/auth", () => {
expectSetAuthCookie(res)
})
})
// SINGLE TENANT
describe("GET /api/global/auth/oidc/callback", () => {})
describe("GET /api/global/auth/oidc/callback", () => {})
describe("GET /api/admin/auth/oidc/callback", () => {})
})
})

View File

@ -1,29 +0,0 @@
import { TestConfiguration } from "../../../../tests"
// TODO
describe("/api/global/workspaces", () => {
const config = new TestConfiguration()
beforeAll(async () => {
await config.beforeAll()
})
afterAll(async () => {
await config.afterAll()
})
afterEach(() => {
jest.clearAllMocks()
})
describe("GET /api/global/workspaces", () => {
it("retrieves workspaces", () => {})
})
describe("DELETE /api/global/workspaces/:id", () => {})
describe("GET /api/global/workspaces", () => {})
describe("GET /api/global/workspaces/:id", () => {})
})