Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

promises support in tests #307

Merged
merged 157 commits into from
Jan 28, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
157 commits
Select commit Hold shift + click to select a range
843aff7
Added expected and actual to TestResults class
chrisdp Jan 6, 2025
c74252b
First pass of MochaTestReporter
chrisdp Jan 6, 2025
6419e5d
Added actual and expected to assertTrue and assertFalse
chrisdp Jan 6, 2025
d7f97f7
New string function and more assert messages
chrisdp Jan 7, 2025
267ae90
Cleaned up message generation
chrisdp Jan 7, 2025
774bec2
Fixed failing unit test
chrisdp Jan 7, 2025
a3453ca
Cleaned up some messaging output
chrisdp Jan 7, 2025
3ed8928
Do not report empty actual and expected diffs
chrisdp Jan 7, 2025
236828e
actual and expected are invalid by default
chrisdp Jan 7, 2025
ba03d16
whitespace clean up
chrisdp Jan 7, 2025
bcd7ad5
Made temp logs less spammy
chrisdp Jan 7, 2025
8aff306
More assertion updates
chrisdp Jan 7, 2025
2e1995c
Updates to most aa and array asserts
chrisdp Jan 7, 2025
bb01de2
clean up on displaying types
chrisdp Jan 7, 2025
a6fc6e0
Updates to assertArrayCount
chrisdp Jan 7, 2025
f7ab474
Updates to assertArrayCount to fix a crash case
chrisdp Jan 7, 2025
d1f51b8
Messaging updates
chrisdp Jan 7, 2025
5fab12c
Updated array count assertions
chrisdp Jan 7, 2025
2371f13
updated assertNotEmpty and assertEmpty
chrisdp Jan 7, 2025
a577667
Fixed a actual/expected filting bug
chrisdp Jan 7, 2025
7fe4d83
Added tests to sample project
chrisdp Jan 7, 2025
2dd6bf5
Fixed a bug with assertArrayNotCount
chrisdp Jan 7, 2025
277cfe7
Updates to assertArrayContainsOnlyValuesOfType and assertType
chrisdp Jan 7, 2025
c007fb4
Fixed a bug in assertArrayContainsOnlyValuesOfType with AA's
chrisdp Jan 7, 2025
6783051
Removed stop statement
chrisdp Jan 8, 2025
9513065
updates to assertArrayNotContainsSubset, assertArrayContainsSubset, a…
chrisdp Jan 8, 2025
ab2329f
updates to assertClass and assertSubType
chrisdp Jan 8, 2025
46b87de
Fixed a bugt in assertArrayNotContainsSubset that would always fail f…
chrisdp Jan 8, 2025
f917c37
updated assertNodeCount
chrisdp Jan 8, 2025
7939844
More updates
chrisdp Jan 8, 2025
f8cd8b5
Updates assets to respect custom failure messages when supplied
chrisdp Jan 8, 2025
ecb6f66
remove only annotation
chrisdp Jan 8, 2025
679d036
Fixed a crash in eqAssocArray
chrisdp Jan 8, 2025
b380a32
Fixed some unexpected failing tests
chrisdp Jan 8, 2025
e88aca9
Fixed some failure messages for assert true and false
chrisdp Jan 8, 2025
deaf794
Tweeks to empty multiline aa and array
chrisdp Jan 8, 2025
550e06f
Fixed a crash reporting node tests due to missing actual and expected…
chrisdp Jan 9, 2025
66c4a92
Fixed a bug related to ignoredFields
chrisdp Jan 9, 2025
b2bda59
Fixed a error log that would print even when there was no error for n…
chrisdp Jan 9, 2025
795890f
Added new test reporter hooks
chrisdp Jan 10, 2025
512ca3a
implimented new hooks and moved logs into reporters
chrisdp Jan 10, 2025
0d821a4
Fixed a falure case that would pass
chrisdp Jan 10, 2025
7f95b67
Include ignored tests but skip their exicution when found
chrisdp Jan 10, 2025
4744887
Moved tests that should fail to their own suite
chrisdp Jan 10, 2025
bd83b11
Removed old commited code
chrisdp Jan 10, 2025
9855d2d
Removed an ignore anotation
chrisdp Jan 10, 2025
707e01c
Fixed some issues with skipped tests
chrisdp Jan 10, 2025
042fe6d
Updated the console test reporter to handle skipped and ignored tests…
chrisdp Jan 10, 2025
99171b3
Fixed a regression in the console test reporter
chrisdp Jan 10, 2025
511d073
Merge branch 'master' into feature/mocha-test-reporter
chrisdp Jan 10, 2025
8ae8b59
Fixed some broken tests
chrisdp Jan 10, 2025
a06bb33
Re-enabled catch on crash
chrisdp Jan 10, 2025
7e0730a
Added new colorizeOutput setting
chrisdp Jan 13, 2025
08a4af1
Formatting fixes
chrisdp Jan 13, 2025
96632fa
linking fixes
chrisdp Jan 13, 2025
f136a16
replaced short hand prints
chrisdp Jan 13, 2025
1ae302f
Moved diffing logic into an internal namespace to prevent code conflicts
chrisdp Jan 13, 2025
e127312
Code clean up
chrisdp Jan 13, 2025
575586e
Updated reporters to take event objects
chrisdp Jan 13, 2025
6dd854e
Updated brighterscript to 0.68.3
chrisdp Jan 13, 2025
4227065
Updated brighterscript to 0.68.3 for test workspace
chrisdp Jan 13, 2025
9b80589
Added a log that will always fire after test reporters
chrisdp Jan 13, 2025
2f72715
Removed some unnessisary prints from mocha reporter
chrisdp Jan 13, 2025
0ae9a04
Doc blocks
chrisdp Jan 13, 2025
be41856
Made stacktraces easier to read and added test file links in crashes
chrisdp Jan 13, 2025
1a163d1
Typo
chrisdp Jan 13, 2025
a0e0fde
More tests
chrisdp Jan 13, 2025
df8b66d
Removed actual and expected from assertNotEqual
chrisdp Jan 13, 2025
87f4689
More failure tests
chrisdp Jan 13, 2025
2ce1601
More failure tests for assertArrayNotContains
chrisdp Jan 13, 2025
daa700a
Cleaned up some tests
chrisdp Jan 14, 2025
5cc1f29
Fixed assertAANotHasKey not marking tests as failed in some cases
chrisdp Jan 14, 2025
60722f1
Fixed crash in assertInvalid
chrisdp Jan 14, 2025
b64f834
Added actual and expected diff for assertAAHasKeys
chrisdp Jan 14, 2025
7ad40e8
Cleaned up some failure messages
chrisdp Jan 14, 2025
0aba70e
More tests and clean up for failed assertions
chrisdp Jan 14, 2025
d8ef0a1
Updated asMultilineString to print invalid and uninitialized as their…
chrisdp Jan 14, 2025
efadf5d
comment typo
chrisdp Jan 14, 2025
d460a87
Code clean up and lots more comments in mocha test reporter
chrisdp Jan 14, 2025
0a2a063
Fixed the reports namespace name to be reporter
chrisdp Jan 14, 2025
fddad40
Moved some logs to a new warning log rather then error
chrisdp Jan 14, 2025
f233caf
updated assertClass to remove actual and expected diff
chrisdp Jan 14, 2025
a4c2a27
Fixed uninitilized not being comparable with eqValues
chrisdp Jan 14, 2025
b77ad70
Fixed mocha results printing
chrisdp Jan 14, 2025
aca45ca
Fixed most failing tests
chrisdp Jan 14, 2025
119a216
Update CommonUtils.bs
chrisdp Jan 15, 2025
120dbc6
Update CommonUtils.bs
chrisdp Jan 15, 2025
154c125
Update TestGroup.bs
chrisdp Jan 15, 2025
9d3404f
Update CodeCoverageProcessor.spec.ts
chrisdp Jan 15, 2025
9f78d7d
installed ropm and promises
chrisdp Jan 15, 2025
d23bae0
added fast glob npm module
chrisdp Jan 15, 2025
bd34cd4
updated FileFactory to use flog to find framework files
chrisdp Jan 15, 2025
69a461d
Updated the framework fold structure to match what will be on device
chrisdp Jan 15, 2025
4fd2173
Fixed build copy command
chrisdp Jan 15, 2025
1a49edc
Code clean up and removed unessisary props following the structure ch…
chrisdp Jan 15, 2025
adda058
Removed options from FileFactory constructor
chrisdp Jan 15, 2025
bdd7a2f
Merge branch 'task/update-framework-folder-to-match-structure-on-devi…
chrisdp Jan 15, 2025
8497348
Merge branch 'feature/mocha-test-reporter' into feature/promises-support
chrisdp Jan 15, 2025
956efaa
Updated the promises prefix and FileFactory to auto import it
chrisdp Jan 15, 2025
be7864d
Moved MochaTestReporter class into source/rooibos
chrisdp Jan 15, 2025
0818b87
Added a couple passing tests for assertInvalid
chrisdp Jan 15, 2025
41516f4
Merge branch 'feature/mocha-test-reporter' into feature/promises-support
chrisdp Jan 15, 2025
9950c80
Added example test showing promises are imported with rooibos tests
chrisdp Jan 15, 2025
5458f56
Always sort keys in aa when generating diff strings
chrisdp Jan 15, 2025
c574196
Added support for reporting slow tests
chrisdp Jan 15, 2025
052b5b0
Fixed failing test
chrisdp Jan 15, 2025
185c17c
Merge branch 'feature/mocha-test-reporter' into feature/promises-support
chrisdp Jan 15, 2025
ab9f3ea
Fixed a rehydration issue
chrisdp Jan 16, 2025
6bce01f
Create differed promises in node tests
chrisdp Jan 16, 2025
841805b
Added some examples returning promises from tests
chrisdp Jan 16, 2025
ab8467c
First pass as promises in node/async tests
chrisdp Jan 16, 2025
437e16d
Added more tests that levrage promises
chrisdp Jan 17, 2025
140830e
Added support for using native nodes in node tests
chrisdp Jan 17, 2025
b30997b
Async tests are now automaticly flagged as Node tests
chrisdp Jan 17, 2025
1b9dcb0
Fixed a thread ownership issue if your node test uses a non-renderabl…
chrisdp Jan 17, 2025
246855d
Reduced the delay in some tests as they did not need to be so long
chrisdp Jan 17, 2025
28bbb17
renammed vars differed to deferred
chrisdp Jan 17, 2025
bbf9b60
Removed threadinto prints
chrisdp Jan 17, 2025
46b5f1c
Fixed some bugs and removed some unused callbacks and node fields
chrisdp Jan 17, 2025
3cf28c5
Updated how results from node tests are passed back to the main threa…
chrisdp Jan 17, 2025
5933ad2
Updated how the test time is recorded and moved some logic into funct…
chrisdp Jan 17, 2025
3c8d745
removed some commented out code
chrisdp Jan 17, 2025
494346f
Fixed failing test
chrisdp Jan 17, 2025
94ddba4
Fixed a bug where function names that start with a number would trans…
chrisdp Jan 17, 2025
608b4f5
Added a suite to test suite level time outs
chrisdp Jan 17, 2025
d495ac8
Added the new timeout logic to the suite and removed lagicy code
chrisdp Jan 17, 2025
daa52a8
Fixed an issue where identical diffs would attempt to be rendered
chrisdp Jan 17, 2025
49e625a
Merge branch 'feature/mocha-test-reporter' into feature/promises-support
chrisdp Jan 17, 2025
07c81a3
Update BaseTestSuite.bs
chrisdp Jan 18, 2025
c8f2978
Update Test.bs
chrisdp Jan 18, 2025
d0b2be6
Moved back to brighterscript 0.67.4
chrisdp Jan 20, 2025
79af99f
Merge branch 'feature/mocha-test-reporter' into feature/promises-support
chrisdp Jan 20, 2025
35707cf
Cleaned up unused field and unnecessary call back
chrisdp Jan 20, 2025
16d4319
Added some tests to prove returning promises fails tests when in non-…
chrisdp Jan 20, 2025
ffc6015
Removed only annotation in spec file
chrisdp Jan 20, 2025
06e9a76
Updated docs with some information on promises
chrisdp Jan 20, 2025
f83efb8
Added an example of how to use assertAsyncField to watch a field on a…
chrisdp Jan 20, 2025
983c164
package-lock update
chrisdp Jan 20, 2025
e0a9362
Log message update
chrisdp Jan 20, 2025
5bc1af7
Fixed typos in docs
chrisdp Jan 20, 2025
68a7138
Added doc for slow annotation
chrisdp Jan 20, 2025
3f387f6
Added tons of tests for passing usecases
chrisdp Jan 20, 2025
f457c41
Merge branch 'feature/mocha-test-reporter' into feature/promises-support
chrisdp Jan 20, 2025
b1a3b57
Update bsc-plugin/src/lib/rooibos/CodeCoverageProcessor.spec.ts
chrisdp Jan 20, 2025
a643ac9
Merge branch 'feature/mocha-test-reporter' into feature/promises-support
chrisdp Jan 20, 2025
6b91e29
New line when tests start
chrisdp Jan 20, 2025
49752ed
Merge branch 'feature/mocha-test-reporter' into feature/promises-support
chrisdp Jan 22, 2025
0c0c045
Remove the `postinstall` script during packaging
TwitchBronBron Jan 22, 2025
3cece92
Give slow test more time to complete
TwitchBronBron Jan 22, 2025
7233987
Fix lint issue
TwitchBronBron Jan 22, 2025
1c7063e
Added assertNotInvalid test for roInvalid
chrisdp Jan 22, 2025
cba39ca
Updated assertInvalid test for roInvalid
chrisdp Jan 22, 2025
b5506e6
hardened assertNotInvalid and fixed assertInvalid for roInvalid
chrisdp Jan 22, 2025
e5f43b4
Fixed some off by oneline number reporting bugs
chrisdp Jan 22, 2025
e042f33
Merge branch 'feature/mocha-test-reporter' into feature/promises-support
chrisdp Jan 22, 2025
d102209
fixes after updating with reporting line number fixes from mocha branch
chrisdp Jan 22, 2025
096efd1
Merge branch 'master' of https://github.com/rokucommunity/rooibos int…
TwitchBronBron Jan 28, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
914 changes: 903 additions & 11 deletions bsc-plugin/package-lock.json

Large diffs are not rendered by default.

10 changes: 9 additions & 1 deletion bsc-plugin/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@
"publish-npm:beta": "npm run test && npm publish --tag=beta",
"local": "ts-node scripts/install-local.js",
"remote": "ts-node scripts/install-npm.js",
"cli": "ts-node src/cli.ts"
"cli": "ts-node src/cli.ts",
"prepack": "node scripts/pack.js --pre",
"postpack": "node scripts/pack.js --post",
"postinstall": "ropm copy"
},
"repository": {
"type": "git",
Expand All @@ -35,6 +38,7 @@
"dependencies": {
"roku-debug": "^0.21.10",
"roku-deploy": "^3.12.1",
"rooibos_promises": "npm:@rokucommunity/promises@^0.5.0",
"source-map": "^0.7.3",
"undent": "^0.1.0",
"vscode-languageserver": "~6.1.1",
Expand Down Expand Up @@ -63,6 +67,7 @@
"mocha": "^9.1.3",
"nyc": "^15.1.0",
"release-it": "^17.6.0",
"ropm": "^0.10.30",
"source-map-support": "^0.5.13",
"trim-whitespace": "^1.3.3",
"ts-node": "^9.0.0",
Expand Down Expand Up @@ -121,6 +126,9 @@
"ts"
]
},
"ropm": {
"rootDir": "../framework/src"
},
"config": {
"commitizen": {
"path": "./node_modules/cz-conventional-changelog"
Expand Down
20 changes: 20 additions & 0 deletions bsc-plugin/scripts/pack.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
var fsExtra = require('fs-extra');
var path = require('path');

var cachePath = path.join(__dirname, 'pack-cache.txt');
var packageJsonPath = path.join(__dirname, '../package.json');

var packageJson = fsExtra.readJsonSync(packageJsonPath);

//store the script and remove it from package.json
if (process.argv.includes('--pre')) {
fsExtra.outputFileSync(cachePath, packageJson.scripts.postinstall);
delete packageJson.scripts.postinstall;

//restore the script
} else if (process.argv.includes('--post')) {
packageJson.scripts.postinstall = fsExtra.readFileSync(cachePath, packageJson.scripts.postinstall).toString();
fsExtra.removeSync(cachePath);
}

fsExtra.outputJsonSync(packageJsonPath, packageJson, { spaces: 4 });
13 changes: 9 additions & 4 deletions bsc-plugin/src/lib/rooibos/Annotation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -141,13 +141,18 @@ export class RooibosAnnotation {
isSolo = getAnnotationsOfType(AnnotationType.Solo).length > 0;
isIgnore = getAnnotationsOfType(AnnotationType.Ignore).length > 0;

for (const annotation of getAnnotationsOfType(AnnotationType.NodeTest)) {
nodeName = annotation.getArguments()[0] as string;
}

for (const annotation of getAnnotationsOfType(AnnotationType.Async)) {
async = true;
asyncTimeout = annotation.getArguments().length === 1 ? parseInt(annotation.getArguments()[0] as any) : -1;
}

for (const annotation of getAnnotationsOfType(AnnotationType.NodeTest)) {
nodeName = annotation.getArguments()[0] as string;
if (nodeName === null) {
// If the test is async, it must be a node test
// Default to `Node` if no node is specified
nodeName = 'Node';
}
}

for (const annotation of getAnnotationsOfType(AnnotationType.Tags)) {
Expand Down
18 changes: 14 additions & 4 deletions bsc-plugin/src/lib/rooibos/FileFactory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export class FileFactory {
this.coverageComponentBrsTemplate = fs.readFileSync(path.join(this.frameworkSourcePath, '/source/rooibos/CodeCoverage.brs'), 'utf8');
}

public addedSourceFrameworkFilePaths: string[] = [];
public sourceFilesToAutoImport: string[] = [];
public addedFrameworkFiles: BscFile[] = [];

public addFrameworkFiles(program: Program) {
Expand All @@ -43,10 +43,10 @@ export class FileFactory {
});

for (let filePath of globedFiles) {
if (/^source[/\\]rooibos[/\\]/g.test(filePath)) {
if (this.shouldAddFileToImportList(filePath)) {
// Save a list of all source files added to the program
// to be imported by node test components
this.addedSourceFrameworkFilePaths.push(filePath);
this.sourceFilesToAutoImport.push(filePath);
}
let sourcePath = path.resolve(this.frameworkSourcePath, filePath);
let fileContents = fs.readFileSync(sourcePath, 'utf8').toString();
Expand All @@ -67,7 +67,7 @@ export class FileFactory {

public createTestXML(name: string, baseName: string, suite?: TestSuite): string {
let scriptImports = [];
for (let filePath of this.addedSourceFrameworkFilePaths) {
for (let filePath of this.sourceFilesToAutoImport) {
scriptImports.push(`<script type="text/brighterscript" uri="pkg:/${filePath}" />`);
}

Expand Down Expand Up @@ -117,6 +117,16 @@ export class FileFactory {
return result !== undefined;
}

private shouldAddFileToImportList(destFilePath): boolean {
const pathDetails = path.parse(destFilePath);
if (pathDetails.dir === 'source' || pathDetails.dir.startsWith('source\\') || pathDetails.dir.startsWith('source/')) {
if (pathDetails.ext === '.brs' || (pathDetails.ext === '.bs' && !pathDetails.name.endsWith('.d'))) {
return true;
}
}
return false;
}

public addFile(program, projectPath: string, contents: string) {
try {
const file = program.setFile({
Expand Down
6 changes: 6 additions & 0 deletions bsc-plugin/src/lib/rooibos/RooibosSession.ts
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,12 @@ export class RooibosSession {
}
let brsFile = this.fileFactory.addFile(program, suite.bsPkgPath, undent`
function init()
m.top.addField("rooibosRunSuite", "boolean", false)
m.top.observeFieldScoped("rooibosRunSuite", "rooibosRunSuite")
end function

function rooibosRunSuite()
m.top.unobserveFieldScoped("rooibosRunSuite")
nodeRunner = Rooibos_TestRunner(m.top.getScene(), m)
m.top.rooibosTestResult = nodeRunner.runInNodeMode("${suite.name}")
end function
Expand Down
1 change: 1 addition & 0 deletions bsc-plugin/src/lib/rooibos/TestGroup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,7 @@ export class TestGroup extends TestBlock {
name: ${sanitizeBsJsonString(this.name)}
isSolo: ${this.isSolo}
isIgnored: ${this.isIgnored}
isAsync: ${this.isAsync}
filename: "${this.pkgPath}"
lineNumber: "${this.annotation.annotation.range.start.line + 1}"
setupFunctionName: "${this.setupFunctionName || ''}"
Expand Down
6 changes: 5 additions & 1 deletion bsc-plugin/src/lib/rooibos/TestSuite.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import * as path from 'path';
import type { AstEditor, BrsFile, ClassStatement } from 'brighterscript';
import { nodes } from 'brighterscript/dist/roku-types';

import { diagnosticNodeTestIllegalNode, diagnosticNodeTestRequiresNode } from '../utils/Diagnostics';

Expand All @@ -9,6 +10,8 @@ import type { TestGroup } from './TestGroup';
import { addOverriddenMethod, sanitizeBsJsonString } from './Utils';
import type { RooibosSession } from './RooibosSession';

const nativeNodeNames = Object.keys(nodes);

/**
* base of test suites and blocks..
*/
Expand Down Expand Up @@ -124,7 +127,7 @@ export class TestSuite extends TestBlock {
if (this.isNodeTest) {
if (!this.nodeName) {
diagnosticNodeTestRequiresNode(this.file, this.annotation.annotation);
} else if (!this.file.program.getComponent(this.nodeName)) {
} else if (!this.file.program.getComponent(this.nodeName) && !nativeNodeNames.includes(this.nodeName.toLowerCase())) {
diagnosticNodeTestIllegalNode(this.file, this.annotation.annotation, this.nodeName);
}
}
Expand All @@ -138,6 +141,7 @@ export class TestSuite extends TestBlock {
isSolo: ${this.isSolo}
noCatch: ${this.annotation.noCatch}
isIgnored: ${this.isIgnored}
isAsync: ${this.isAsync}
pkgPath: "${this.pkgPath}"
filePath: "${this.filePath}"
lineNumber: ${this.classStatement.range.start.line + 1}
Expand Down
3 changes: 3 additions & 0 deletions bsc-plugin/src/lib/rooibos/TestSuiteBuilder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,9 @@ export class TestSuiteBuilder {
}

private sanitizeFunctionName(name: string) {
if (/^\d/.test(name)) {
name = '_' + name;
}
return name.replace(/[^0-9_a-z]/ig, '_');
}
public createTestCases(statement: ClassMethodStatement, annotation: RooibosAnnotation): boolean {
Expand Down
123 changes: 122 additions & 1 deletion bsc-plugin/src/plugin.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -488,6 +488,7 @@ describe('RooibosPlugin', () => {
isSolo: false
noCatch: false
isIgnored: false
isAsync: false
pkgPath: "${s`source/test.spec.bs`}"
filePath: "${s`${tmpPath}/rootDir/source/test.spec.bs`}"
lineNumber: 3
Expand All @@ -510,6 +511,7 @@ describe('RooibosPlugin', () => {
name: "groupA"
isSolo: false
isIgnored: false
isAsync: false
filename: "${s`source/test.spec.bs`}"
lineNumber: "4"
setupFunctionName: ""
Expand Down Expand Up @@ -556,6 +558,124 @@ describe('RooibosPlugin', () => {
})).not.to.exist;
});

it('handles groups that start with numbers', async () => {
plugin.afterProgramCreate(program);
// program.validate();
const file = program.setFile<BrsFile>('source/test.spec.bs', `
@suite
class ATest extends rooibos.BaseTestSuite
@describe("1groupA")
@it("is test1")
@slow(1000)
function Test_3()
end function
end class
`);
program.validate();
await builder.transpile();
console.log(builder.getDiagnostics());
expect(builder.getDiagnostics()).to.have.length(1);
expect(builder.getDiagnostics()[0].severity).to.equal(DiagnosticSeverity.Warning);
expect(plugin.session.sessionInfo.testSuitesToRun).to.not.be.empty;
expect(plugin.session.sessionInfo.suitesCount).to.equal(1);
expect(plugin.session.sessionInfo.groupsCount).to.equal(1);
expect(plugin.session.sessionInfo.testsCount).to.equal(1);

expect(
getContents('rooibosMain.brs')
).to.eql(undent`
function main()
Rooibos_init("RooibosScene")
end function
`);
expect(
getContents('test.spec.brs')
).to.eql(undent`
function __ATest_builder()
instance = __rooibos_BaseTestSuite_builder()
instance.super0_new = instance.new
instance.new = sub()
m.super0_new()
end sub
instance._1groupA_is_test1 = function()
end function
instance.super0_getTestSuiteData = instance.getTestSuiteData
instance.getTestSuiteData = function()
return {
name: "ATest"
isSolo: false
noCatch: false
isIgnored: false
isAsync: false
pkgPath: "${s`source/test.spec.bs`}"
filePath: "${s`${tmpPath}/rootDir/source/test.spec.bs`}"
lineNumber: 3
valid: true
hasFailures: false
hasSoloTests: false
hasIgnoredTests: false
hasSoloGroups: false
setupFunctionName: ""
tearDownFunctionName: ""
beforeEachFunctionName: ""
afterEachFunctionName: ""
isNodeTest: false
isAsync: false
asyncTimeout: 60000
nodeName: ""
generatedNodeName: "ATest"
testGroups: [
{
name: "1groupA"
isSolo: false
isIgnored: false
isAsync: false
filename: "${s`source/test.spec.bs`}"
lineNumber: "4"
setupFunctionName: ""
tearDownFunctionName: ""
beforeEachFunctionName: ""
afterEachFunctionName: ""
testCases: [
{
isSolo: false
noCatch: false
funcName: "_1groupA_is_test1"
isIgnored: false
isAsync: false
asyncTimeout: 2000
slow: 1000
isParamTest: false
name: "is test1"
lineNumber: 7
paramLineNumber: 0
assertIndex: 0
rawParams: invalid
paramTestIndex: 0
expectedNumberOfParams: 0
isParamsValid: true
}
]
}
]
}
end function
return instance
end function
function ATest()
instance = __ATest_builder()
instance.new()
return instance
end function
`);

//verify the AST was restored after transpile
const cls = file.ast.statements[0] as ClassStatement;
expect(cls.body.find((x: ClassMethodStatement) => {
return x.name?.text.toLowerCase() === 'getTestSuiteData'.toLowerCase();
})).not.to.exist;
});

it('test full transpile with complex params', async () => {
plugin.afterProgramCreate(program);
// program.validate();
Expand Down Expand Up @@ -2174,7 +2294,8 @@ describe('RooibosPlugin', () => {
[['mocha'], 'rooibos_MochaTestReporter'],
[['JUnit', 'MyCustomReporter'], `rooibos_JUnitTestReporter${sep}MyCustomReporter`]
];
it('adds custom test reporters', async () => {
it('adds custom test reporters', async function test() {
this.timeout(10_000);
for (const [reporters, expected] of params) {
setupProgram({
rootDir: _rootDir,
Expand Down
21 changes: 20 additions & 1 deletion docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -1064,7 +1064,7 @@ The behavior of your unit tests is identical to unit testing any other class, wi
### Async testing
To indicate a test suite will run in async mode you will mark the test suite with the @async annotation or mark one ore more tests with @async. This will cause rooibos to run the tests in async mode. If all tests in the suite do not complete within the timeout, then the suite will fail. The default time out is 60 seconds.

When you mark any test in a suite with the @async annotation this will keep the test running in the background, waiting for a call to m.done(). If the call is not made within the timeout, then the test fails. Again, the default timeout for each test is 2 seconds.
When you mark any test in a suite with the @async annotation this will keep the test running in the background, waiting for a call to `m.done()`. If the call is not made within the timeout, then the test fails. Again, the default timeout for each test is 2 seconds.

Note: you are not required to add @async to your testSuite, it is implied when you add it one more more tests. However, you may wish to add tge async annotation to your suite, to override the default of 60 seconds (e.g. with the annotation `async(12000)` we are instructing rooibos to wait up to 2 minutes for the _whole_ suite).

Expand Down Expand Up @@ -1142,7 +1142,26 @@ function OnTimer()
m.testSuite.done()
end function
```
#### Working with Promises

Alternately, instead of using the `done()` callback, you may return a `Promise` from your test. The test will automaticly complete when the promise is completed. If the returned promise rejects the test will be considered failed.

This is useful if the APIs you are testing return promises:

```
@it('respond with matching records')
function _()
return rooibos.promises.chain(db.find({type: 'User'})).then(sub(result)
m.testSuite.assertEqual(result.count(), 3)
end sub).catch(sub(error)
m.testSuite.fail("should not reject")
end sub).toPromises()
end function
```

Rooibos implements the [rokucomunity/promises](https://github.com/rokucommunity/promises) library to enable this support. Please visit that project for more details and examples of promises.

Note: `Promises` are only supported in Node tests and returning a promise from a non-Node test will automaticly fail the test.

## Advanced setup

Expand Down
Loading
Loading