refactor: lint

This commit is contained in:
liyasthomas
2021-05-18 14:57:29 +05:30
parent 7f248da0b3
commit cc27c552af
84 changed files with 1444 additions and 973 deletions

View File

@@ -1,6 +1,8 @@
import { cancelRunningRequest, sendNetworkRequest } from "../network"
import AxiosStrategy, { cancelRunningAxiosRequest } from "../strategies/AxiosStrategy"
import AxiosStrategy, {
cancelRunningAxiosRequest,
} from "../strategies/AxiosStrategy"
import ExtensionStrategy, {
cancelRunningExtensionRequest,
hasExtensionInstalled,
@@ -23,9 +25,9 @@ jest.mock("~/newstore/settings", () => {
return {
settingsStore: {
value: {
EXTENSIONS_ENABLED: false
}
}
EXTENSIONS_ENABLED: false,
},
},
}
})
@@ -60,7 +62,6 @@ describe("cancelRunningRequest", () => {
})
describe("sendNetworkRequest", () => {
test("runs only axios request if extension not allowed in settings and extension is installed and clears the progress bar", async () => {
hasExtensionInstalled.mockReturnValue(true)

View File

@@ -1,7 +1,8 @@
import { cancelRunningRequest, sendNetworkRequest } from "../network"
import AxiosStrategy, { cancelRunningAxiosRequest } from "../strategies/AxiosStrategy"
import AxiosStrategy, {
cancelRunningAxiosRequest,
} from "../strategies/AxiosStrategy"
import ExtensionStrategy, {
cancelRunningExtensionRequest,
hasExtensionInstalled,
@@ -24,9 +25,9 @@ jest.mock("~/newstore/settings", () => {
return {
settingsStore: {
value: {
EXTENSIONS_ENABLED: true
}
}
EXTENSIONS_ENABLED: true,
},
},
}
})

View File

@@ -1,5 +1,4 @@
import { PASS, FAIL } from "../postwomanTesting"
import runTestScriptWithVariables from "../postwomanTesting"
import runTestScriptWithVariables, { PASS, FAIL } from "../postwomanTesting"
function getTestResult(script, index) {
return runTestScriptWithVariables(script).testResults[index].result
@@ -41,8 +40,12 @@ describe("toBe", () => {
test("test for negative assertion (.not.toBe)", () => {
expect(getTestResult("pw.expect(1).not.toBe(1)", 0)).toEqual(FAIL)
expect(getTestResult("pw.expect(1).not.toBe(2)", 0)).toEqual(PASS)
expect(getTestResult("pw.expect('world').not.toBe('planet')", 0)).toEqual(PASS)
expect(getTestResult("pw.expect('world').not.toBe('world')", 0)).toEqual(FAIL)
expect(getTestResult("pw.expect('world').not.toBe('planet')", 0)).toEqual(
PASS
)
expect(getTestResult("pw.expect('world').not.toBe('world')", 0)).toEqual(
FAIL
)
})
})
@@ -54,16 +57,29 @@ describe("toHaveProperty", () => {
test("test for positive assertion (.toHaveProperty)", () => {
expect(
getTestResult(`pw.expect(${JSON.stringify(dummyResponse)}).toHaveProperty("id")`, 0)
getTestResult(
`pw.expect(${JSON.stringify(dummyResponse)}).toHaveProperty("id")`,
0
)
).toEqual(PASS)
expect(
getTestResult(`pw.expect(${dummyResponse.id}).toBe(843)`, 0)
).toEqual(PASS)
expect(getTestResult(`pw.expect(${dummyResponse.id}).toBe(843)`, 0)).toEqual(PASS)
})
test("test for negative assertion (.not.toHaveProperty)", () => {
expect(
getTestResult(`pw.expect(${JSON.stringify(dummyResponse)}).not.toHaveProperty("type")`, 0)
getTestResult(
`pw.expect(${JSON.stringify(
dummyResponse
)}).not.toHaveProperty("type")`,
0
)
).toEqual(PASS)
expect(
getTestResult(`pw.expect(${JSON.stringify(dummyResponse)}).toHaveProperty("type")`, 0)
getTestResult(
`pw.expect(${JSON.stringify(dummyResponse)}).toHaveProperty("type")`,
0
)
).toEqual(FAIL)
})
})
@@ -77,12 +93,18 @@ describe("toBeLevel2xx", () => {
})
test("test for strings", () => {
expect(getTestResult("pw.expect('200').toBeLevel2xx()", 0)).toEqual(PASS)
expect(getTestResult("pw.expect('200').not.toBeLevel2xx()", 0)).toEqual(FAIL)
expect(getTestResult("pw.expect('200').not.toBeLevel2xx()", 0)).toEqual(
FAIL
)
expect(getTestResult("pw.expect('300').toBeLevel2xx()", 0)).toEqual(FAIL)
expect(getTestResult("pw.expect('300').not.toBeLevel2xx()", 0)).toEqual(PASS)
expect(getTestResult("pw.expect('300').not.toBeLevel2xx()", 0)).toEqual(
PASS
)
})
test("failed to parse to integer", () => {
expect(getTestResult("pw.expect(undefined).toBeLevel2xx()", 0)).toEqual(FAIL)
expect(getTestResult("pw.expect(undefined).toBeLevel2xx()", 0)).toEqual(
FAIL
)
expect(getTestResult("pw.expect(null).toBeLevel2xx()", 0)).toEqual(FAIL)
expect(() => {
runTestScriptWithVariables("pw.expect(Symbol('test')).toBeLevel2xx()")
@@ -99,12 +121,18 @@ describe("toBeLevel3xx()", () => {
})
test("test for strings", () => {
expect(getTestResult("pw.expect('300').toBeLevel3xx()", 0)).toEqual(PASS)
expect(getTestResult("pw.expect('300').not.toBeLevel3xx()", 0)).toEqual(FAIL)
expect(getTestResult("pw.expect('300').not.toBeLevel3xx()", 0)).toEqual(
FAIL
)
expect(getTestResult("pw.expect('400').toBeLevel3xx()", 0)).toEqual(FAIL)
expect(getTestResult("pw.expect('400').not.toBeLevel3xx()", 0)).toEqual(PASS)
expect(getTestResult("pw.expect('400').not.toBeLevel3xx()", 0)).toEqual(
PASS
)
})
test("failed to parse to integer", () => {
expect(getTestResult("pw.expect(undefined).toBeLevel3xx()", 0)).toEqual(FAIL)
expect(getTestResult("pw.expect(undefined).toBeLevel3xx()", 0)).toEqual(
FAIL
)
expect(getTestResult("pw.expect(null).toBeLevel3xx()", 0)).toEqual(FAIL)
expect(() => {
runTestScriptWithVariables("pw.expect(Symbol('test')).toBeLevel3xx()")
@@ -121,12 +149,18 @@ describe("toBeLevel4xx()", () => {
})
test("test for strings", () => {
expect(getTestResult("pw.expect('400').toBeLevel4xx()", 0)).toEqual(PASS)
expect(getTestResult("pw.expect('400').not.toBeLevel4xx()", 0)).toEqual(FAIL)
expect(getTestResult("pw.expect('400').not.toBeLevel4xx()", 0)).toEqual(
FAIL
)
expect(getTestResult("pw.expect('500').toBeLevel4xx()", 0)).toEqual(FAIL)
expect(getTestResult("pw.expect('500').not.toBeLevel4xx()", 0)).toEqual(PASS)
expect(getTestResult("pw.expect('500').not.toBeLevel4xx()", 0)).toEqual(
PASS
)
})
test("failed to parse to integer", () => {
expect(getTestResult("pw.expect(undefined).toBeLevel4xx()", 0)).toEqual(FAIL)
expect(getTestResult("pw.expect(undefined).toBeLevel4xx()", 0)).toEqual(
FAIL
)
expect(getTestResult("pw.expect(null).toBeLevel4xx()", 0)).toEqual(FAIL)
expect(() => {
runTestScriptWithVariables("pw.expect(Symbol('test')).toBeLevel4xx()")
@@ -143,12 +177,18 @@ describe("toBeLevel5xx()", () => {
})
test("test for strings", () => {
expect(getTestResult("pw.expect('500').toBeLevel5xx()", 0)).toEqual(PASS)
expect(getTestResult("pw.expect('500').not.toBeLevel5xx()", 0)).toEqual(FAIL)
expect(getTestResult("pw.expect('500').not.toBeLevel5xx()", 0)).toEqual(
FAIL
)
expect(getTestResult("pw.expect('200').toBeLevel5xx()", 0)).toEqual(FAIL)
expect(getTestResult("pw.expect('200').not.toBeLevel5xx()", 0)).toEqual(PASS)
expect(getTestResult("pw.expect('200').not.toBeLevel5xx()", 0)).toEqual(
PASS
)
})
test("failed to parse to integer", () => {
expect(getTestResult("pw.expect(undefined).toBeLevel5xx()", 0)).toEqual(FAIL)
expect(getTestResult("pw.expect(undefined).toBeLevel5xx()", 0)).toEqual(
FAIL
)
expect(getTestResult("pw.expect(null).toBeLevel5xx()", 0)).toEqual(FAIL)
expect(() => {
runTestScriptWithVariables("pw.expect(Symbol('test')).toBeLevel5xx()")
@@ -160,40 +200,85 @@ describe("toHaveLength()", () => {
test("test for strings", () => {
expect(getTestResult("pw.expect('word').toHaveLength(4)", 0)).toEqual(PASS)
expect(getTestResult("pw.expect('word').toHaveLength(5)", 0)).toEqual(FAIL)
expect(getTestResult("pw.expect('word').not.toHaveLength(4)", 0)).toEqual(FAIL)
expect(getTestResult("pw.expect('word').not.toHaveLength(5)", 0)).toEqual(PASS)
expect(getTestResult("pw.expect('word').not.toHaveLength(4)", 0)).toEqual(
FAIL
)
expect(getTestResult("pw.expect('word').not.toHaveLength(5)", 0)).toEqual(
PASS
)
})
test("test for arrays", () => {
const fruits = "['apples', 'bananas', 'oranges', 'grapes', 'strawberries', 'cherries']"
expect(getTestResult(`pw.expect(${fruits}).toHaveLength(6)`, 0)).toEqual(PASS)
expect(getTestResult(`pw.expect(${fruits}).toHaveLength(7)`, 0)).toEqual(FAIL)
expect(getTestResult(`pw.expect(${fruits}).not.toHaveLength(6)`, 0)).toEqual(FAIL)
expect(getTestResult(`pw.expect(${fruits}).not.toHaveLength(7)`, 0)).toEqual(PASS)
const fruits =
"['apples', 'bananas', 'oranges', 'grapes', 'strawberries', 'cherries']"
expect(getTestResult(`pw.expect(${fruits}).toHaveLength(6)`, 0)).toEqual(
PASS
)
expect(getTestResult(`pw.expect(${fruits}).toHaveLength(7)`, 0)).toEqual(
FAIL
)
expect(
getTestResult(`pw.expect(${fruits}).not.toHaveLength(6)`, 0)
).toEqual(FAIL)
expect(
getTestResult(`pw.expect(${fruits}).not.toHaveLength(7)`, 0)
).toEqual(PASS)
})
})
describe("toBeType()", () => {
test("test for positive assertion", () => {
expect(getTestResult("pw.expect('random').toBeType('string')", 0)).toEqual(PASS)
expect(getTestResult("pw.expect(true).toBeType('boolean')", 0)).toEqual(PASS)
expect(getTestResult("pw.expect('random').toBeType('string')", 0)).toEqual(
PASS
)
expect(getTestResult("pw.expect(true).toBeType('boolean')", 0)).toEqual(
PASS
)
expect(getTestResult("pw.expect(5).toBeType('number')", 0)).toEqual(PASS)
expect(getTestResult("pw.expect(new Date()).toBeType('object')", 0)).toEqual(PASS)
expect(getTestResult("pw.expect(undefined).toBeType('undefined')", 0)).toEqual(PASS)
expect(getTestResult("pw.expect(BigInt(123)).toBeType('bigint')", 0)).toEqual(PASS)
expect(getTestResult("pw.expect(Symbol('test')).toBeType('symbol')", 0)).toEqual(PASS)
expect(getTestResult("pw.expect(function() {}).toBeType('function')", 0)).toEqual(PASS)
expect(
getTestResult("pw.expect(new Date()).toBeType('object')", 0)
).toEqual(PASS)
expect(
getTestResult("pw.expect(undefined).toBeType('undefined')", 0)
).toEqual(PASS)
expect(
getTestResult("pw.expect(BigInt(123)).toBeType('bigint')", 0)
).toEqual(PASS)
expect(
getTestResult("pw.expect(Symbol('test')).toBeType('symbol')", 0)
).toEqual(PASS)
expect(
getTestResult("pw.expect(function() {}).toBeType('function')", 0)
).toEqual(PASS)
})
test("test for negative assertion", () => {
expect(getTestResult("pw.expect('random').not.toBeType('string')", 0)).toEqual(FAIL)
expect(getTestResult("pw.expect(true).not.toBeType('boolean')", 0)).toEqual(FAIL)
expect(getTestResult("pw.expect(5).not.toBeType('number')", 0)).toEqual(FAIL)
expect(getTestResult("pw.expect(new Date()).not.toBeType('object')", 0)).toEqual(FAIL)
expect(getTestResult("pw.expect(undefined).not.toBeType('undefined')", 0)).toEqual(FAIL)
expect(getTestResult("pw.expect(BigInt(123)).not.toBeType('bigint')", 0)).toEqual(FAIL)
expect(getTestResult("pw.expect(Symbol('test')).not.toBeType('symbol')", 0)).toEqual(FAIL)
expect(getTestResult("pw.expect(function() {}).not.toBeType('function')", 0)).toEqual(FAIL)
expect(
getTestResult("pw.expect('random').not.toBeType('string')", 0)
).toEqual(FAIL)
expect(getTestResult("pw.expect(true).not.toBeType('boolean')", 0)).toEqual(
FAIL
)
expect(getTestResult("pw.expect(5).not.toBeType('number')", 0)).toEqual(
FAIL
)
expect(
getTestResult("pw.expect(new Date()).not.toBeType('object')", 0)
).toEqual(FAIL)
expect(
getTestResult("pw.expect(undefined).not.toBeType('undefined')", 0)
).toEqual(FAIL)
expect(
getTestResult("pw.expect(BigInt(123)).not.toBeType('bigint')", 0)
).toEqual(FAIL)
expect(
getTestResult("pw.expect(Symbol('test')).not.toBeType('symbol')", 0)
).toEqual(FAIL)
expect(
getTestResult("pw.expect(function() {}).not.toBeType('function')", 0)
).toEqual(FAIL)
})
test("unexpected type", () => {
expect(getTestResult("pw.expect('random').toBeType('unknown')", 0)).toEqual(FAIL)
expect(getTestResult("pw.expect('random').toBeType('unknown')", 0)).toEqual(
FAIL
)
})
})