Skip to content

Commit

Permalink
Move test fixtures to independent workspace & add more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jribbink committed Dec 6, 2023
1 parent 7049d46 commit 1d052eb
Show file tree
Hide file tree
Showing 6 changed files with 85 additions and 2 deletions.
21 changes: 21 additions & 0 deletions extension/test/fixtures/6 - workspace/flow.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"emulators": {
"default": {
"port": 3569,
"serviceAccount": "emulator-account"
}
},
"contracts": {},
"networks": {
"emulator": "127.0.0.1:3569",
"mainnet": "access.mainnet.nodes.onflow.org:9000",
"testnet": "access.devnet.nodes.onflow.org:9000"
},
"accounts": {
"emulator-account": {
"address": "f8d6e0586b0a20c7",
"key": "d2f9b3e122aa5289fb38edab611c8d1c2aa88d6fd8e3943a306a493361639812"
}
},
"deployments": {}
}
66 changes: 64 additions & 2 deletions extension/test/integration/6 - test-provider.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { beforeEach, afterEach } from 'mocha'
import { beforeEach, afterEach, before } from 'mocha'
import { TestProvider } from '../../src/test-provider/test-provider'
import { Settings } from '../../src/settings/settings'
import { FlowConfig } from '../../src/server/flow-config'
Expand All @@ -8,12 +8,19 @@ import * as vscode from 'vscode'
import * as sinon from 'sinon'
import * as assert from 'assert'

const workspacePath = path.resolve(__dirname, './fixtures/workspace')
const workspacePath = path.resolve(__dirname, './fixtures/6 - workspace')

suite('test provider tests', () => {
let mockSettings: Settings
let mockConfig: FlowConfig
let testProvider: TestProvider
let cleanupFunctions: (() => void | Promise<void>)[] = []

before(async function () {
this.timeout(5000)
vscode.workspace.updateWorkspaceFolders(0, vscode.workspace.workspaceFolders?.length ?? 0, { uri: vscode.Uri.file(workspacePath) })
await new Promise((resolve) => setTimeout(resolve, 2500))
})

beforeEach(async function () {
this.timeout(5000)
Expand Down Expand Up @@ -42,6 +49,9 @@ suite('test provider tests', () => {
this.timeout(5000)

testProvider.dispose()
for (const cleanupFunction of cleanupFunctions) {
await cleanupFunction()
}
})

test('runs all tests in workspace and reports results', async function () {
Expand Down Expand Up @@ -110,4 +120,56 @@ suite('test provider tests', () => {
])
assert.deepStrictEqual(failedTests, [])
}).timeout(20000)

test('runs tests including newly created file', async function () {
// Create new file
const testFilePath = path.join(workspacePath, 'test/bar/test4.cdc')
const testFileContents = `
import Test
pub fun testPassing(): Bool {
return assert(true)
}
`
await vscode.workspace.fs.writeFile(vscode.Uri.file(testFilePath), Buffer.from(testFileContents))
cleanupFunctions.push(async () => {
await vscode.workspace.fs.delete(vscode.Uri.file(testFilePath))
})
await new Promise<void>(resolve => setTimeout(resolve, 1000))

// Run tests
let runSpy: sinon.SinonSpiedInstance<vscode.TestRun> | undefined
await new Promise<void>(resolve => {
void testProvider.runAllTests(undefined, (testRun) => {
const originalEnd = testRun.end
testRun.end = () => {
originalEnd.call(testRun)
resolve()
}

runSpy = sinon.spy(testRun)
return runSpy
})
})
if (runSpy == null) throw new Error('runSpy is null')

const passedTests = runSpy.passed.getCalls().map(call => ({ filepath: (call.args[0].uri as vscode.Uri).fsPath, id: call.args[0].id }))
const failedTests = runSpy.failed.getCalls().map(call => ({ filepath: (call.args[0].uri as vscode.Uri).fsPath, id: call.args[0].id, message: (call.args[1] as any).message }))

passedTests.sort((a, b) => a.filepath.localeCompare(b.filepath))
failedTests.sort((a, b) => a.filepath.localeCompare(b.filepath))

assert.strictEqual(passedTests.length + failedTests.length, 6)
assert.deepStrictEqual(passedTests, [
{ filepath: path.join(workspacePath, 'test/bar/test2.cdc'), id: ':testPassing' },
{ filepath: path.join(workspacePath, 'test/bar/test3.cdc'), id: ':testPassing' },
{ filepath: path.join(workspacePath, 'test/bar/test4.cdc'), id: ':testPassing' },
{ filepath: path.join(workspacePath, 'test/test1.cdc'), id: ':testPassing' }
])
assert.deepStrictEqual(failedTests, [
{ filepath: path.join(workspacePath, 'test/bar/test2.cdc'), id: ':testFailing', message: 'FAIL: Execution failed:\nerror: assertion failed\n --> 7465737400000000000000000000000000000000000000000000000000000000:8:2\n' },
{ filepath: path.join(workspacePath, 'test/bar/test3.cdc'), id: ':testFailing', message: 'FAIL: Execution failed:\nerror: assertion failed\n --> 7465737400000000000000000000000000000000000000000000000000000000:4:2\n' }
])

vscode.workspace.updateWorkspaceFolders(0, 1)
}).timeout(20000)
})
Empty file.

0 comments on commit 1d052eb

Please sign in to comment.