From f3cd5ee7ff27c7395363fc6133ec1a6120e628bc Mon Sep 17 00:00:00 2001 From: Vasyl Martynych Date: Wed, 14 Apr 2021 01:31:43 +0300 Subject: [PATCH 1/6] added cleaning testData before running each test file. added testData to docs. --- docs/api/reference/globals.md | 1 + docs/api/reference/test-utilities.md | 20 ++++++++++++++++++++ src/runner/JestRunner.ts | 3 ++- src/runner/TestRunner.ts | 3 ++- 4 files changed, 25 insertions(+), 2 deletions(-) diff --git a/docs/api/reference/globals.md b/docs/api/reference/globals.md index db294ea..18bd7bd 100644 --- a/docs/api/reference/globals.md +++ b/docs/api/reference/globals.md @@ -57,6 +57,7 @@ These extensions are all available on a global associative array called `_brs_`: { getStackTrace: function, global: associative array, + testData: associative array, mockComponent: function, mockComponentPartial: function, mockFunction: function, diff --git a/docs/api/reference/test-utilities.md b/docs/api/reference/test-utilities.md index 7818779..1490e10 100644 --- a/docs/api/reference/test-utilities.md +++ b/docs/api/reference/test-utilities.md @@ -57,6 +57,26 @@ print _brs_.global ------------ +## \_brs_.testData + +A reference to the temporary associative array, so that you can access it from everywhere inside your brs code. Mostly used for saving/accessing some test-specific data. Clears before running each test file. + +### Usage +```brightscript +_brs_.testData._isFooAvailable = false +_brs_.mockFunction("isFooAvailable", sub() + return _brs_.testData._isFooAvailable +end sub) + +isFooAvailable() ' => false + +_brs_.testData._isFooAvailable = true ' something happened and now it is available +isFooAvailable() ' => true +``` +
+ +------------ + # \_brs_.process Allows you to access the command line arguments and locale. diff --git a/src/runner/JestRunner.ts b/src/runner/JestRunner.ts index 881312f..1ded8fc 100644 --- a/src/runner/JestRunner.ts +++ b/src/runner/JestRunner.ts @@ -1,5 +1,5 @@ import { Config } from "@jest/types"; -import { ExecuteWithScope, types as BrsTypes } from "brs"; +import { resetTestData, ExecuteWithScope, types as BrsTypes } from "brs"; import { JestReporter } from "../reporter/JestReporter"; import { TestRunner } from "./TestRunner"; @@ -33,6 +33,7 @@ export class JestRunner extends TestRunner { testFiles.forEach((filename, index) => { this.reporter.onFileStart(filename); try { + resetTestData(); execute([filename], [executeArgs]); } catch (reason) { this.reporter.onFileExecError(filename, index, reason); diff --git a/src/runner/TestRunner.ts b/src/runner/TestRunner.ts index 8c52707..336cf9b 100644 --- a/src/runner/TestRunner.ts +++ b/src/runner/TestRunner.ts @@ -1,5 +1,5 @@ import * as path from "path"; -import { types as BrsTypes, ExecuteWithScope } from "brs"; +import { resetTestData, types as BrsTypes, ExecuteWithScope } from "brs"; import { formatInterpreterError } from "../util"; export class TestRunner { @@ -41,6 +41,7 @@ export class TestRunner { // Set the index so that our TAP reporting is correct. executeArgs.elements.set("index", new BrsTypes.Int32(index)); try { + resetTestData(); execute([filename], [executeArgs]); } catch (e) { console.error( From 37f98977720e41e0eed6627dfd61cc3f8b113870 Mon Sep 17 00:00:00 2001 From: Vasyl Martynych Date: Wed, 14 Apr 2021 23:31:51 +0300 Subject: [PATCH 2/6] add UT to test whether testData clear between different test files --- test/before-after/before-after.test.js | 6 ++++-- test/before-after/mixed/tests/01-nested.test.brs | 10 ++++++++++ test/before-after/mixed/tests/02-single-level.test.brs | 10 ++++++++++ 3 files changed, 24 insertions(+), 2 deletions(-) diff --git a/test/before-after/before-after.test.js b/test/before-after/before-after.test.js index 8683a87..ec9a45a 100644 --- a/test/before-after/before-after.test.js +++ b/test/before-after/before-after.test.js @@ -72,8 +72,8 @@ describe("before-after", () => { expect(results.stats).toMatchObject({ suites: 4, - tests: 12, - passes: 9, + tests: 14, + passes: 11, pending: 3, failures: 0, }); @@ -85,9 +85,11 @@ describe("before-after", () => { { fullTitle: "nested root case 1" }, { fullTitle: "nested root case 2" }, { fullTitle: "nested root case 3" }, + { fullTitle: "nested root check _brs_.testData" }, { fullTitle: "single-level root case 1" }, { fullTitle: "single-level root case 2" }, { fullTitle: "single-level root case 3" }, + { fullTitle: "single-level root check _brs_.testData" }, ]); }); }); diff --git a/test/before-after/mixed/tests/01-nested.test.brs b/test/before-after/mixed/tests/01-nested.test.brs index 5f0553c..03320c3 100644 --- a/test/before-after/mixed/tests/01-nested.test.brs +++ b/test/before-after/mixed/tests/01-nested.test.brs @@ -31,6 +31,16 @@ function main(args as object) as object m.assert.equal(m.counterB, 11, "counterB must be incremented for each test case") end sub) + m.it("check _brs_.testData", sub() + m.assert.isTrue(_brs_.testData <> invalid, "_brs_.testData should be presented") + m.assert.isTrue(_brs_.testData.count() = 0, "by default _brs_.testData should be equal to {}") + + ' change value to check wheter it clear between different test files + _brs_.testData = { + ctx: "file 1" + } + end sub) + m.describe("suite 1", sub() m.addContext({ counterC: 0 diff --git a/test/before-after/mixed/tests/02-single-level.test.brs b/test/before-after/mixed/tests/02-single-level.test.brs index cece314..aa9d5d0 100644 --- a/test/before-after/mixed/tests/02-single-level.test.brs +++ b/test/before-after/mixed/tests/02-single-level.test.brs @@ -37,5 +37,15 @@ function main(args as object) as object m.assert.isInvalid(m.counterB, "afterEach state must not spread to sibling suites") m.assert.equal(m.counterA, 5, "counterA must be incremented for each test case") end sub) + + m.it("check _brs_.testData", sub() + m.assert.isTrue(_brs_.testData <> invalid, "_brs_.testData should be presented") + m.assert.isTrue(_brs_.testData.count() = 0, "by default _brs_.testData should be equal to {}") + + ' change value to check wheter it clear between different test files + _brs_.testData = { + ctx: "file 1" + } + end sub) end sub) end function From 95a15bc1fa087a10eb083d4b376c689713cb61ae Mon Sep 17 00:00:00 2001 From: Vasya-M <33808928+Vasya-M@users.noreply.github.com> Date: Tue, 20 Apr 2021 01:18:08 +0300 Subject: [PATCH 3/6] Update test/before-after/mixed/tests/02-single-level.test.brs fix typo Co-authored-by: Levi Kipke --- test/before-after/mixed/tests/02-single-level.test.brs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/before-after/mixed/tests/02-single-level.test.brs b/test/before-after/mixed/tests/02-single-level.test.brs index aa9d5d0..df3635b 100644 --- a/test/before-after/mixed/tests/02-single-level.test.brs +++ b/test/before-after/mixed/tests/02-single-level.test.brs @@ -42,7 +42,7 @@ function main(args as object) as object m.assert.isTrue(_brs_.testData <> invalid, "_brs_.testData should be presented") m.assert.isTrue(_brs_.testData.count() = 0, "by default _brs_.testData should be equal to {}") - ' change value to check wheter it clear between different test files + ' change value to check whether it clears between different test files _brs_.testData = { ctx: "file 1" } From d4aef5519b208c4e22cb4995550f4e553bf609b8 Mon Sep 17 00:00:00 2001 From: Vasya-M <33808928+Vasya-M@users.noreply.github.com> Date: Tue, 20 Apr 2021 01:18:16 +0300 Subject: [PATCH 4/6] Update test/before-after/mixed/tests/01-nested.test.brs fix typo Co-authored-by: Levi Kipke --- test/before-after/mixed/tests/01-nested.test.brs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/before-after/mixed/tests/01-nested.test.brs b/test/before-after/mixed/tests/01-nested.test.brs index 03320c3..b28514b 100644 --- a/test/before-after/mixed/tests/01-nested.test.brs +++ b/test/before-after/mixed/tests/01-nested.test.brs @@ -35,7 +35,7 @@ function main(args as object) as object m.assert.isTrue(_brs_.testData <> invalid, "_brs_.testData should be presented") m.assert.isTrue(_brs_.testData.count() = 0, "by default _brs_.testData should be equal to {}") - ' change value to check wheter it clear between different test files + ' change value to check whether it clears between different test files _brs_.testData = { ctx: "file 1" } From 8f373af83bd2d0d40e9442d9edec649ce837e308 Mon Sep 17 00:00:00 2001 From: Vasyl Martynych Date: Wed, 21 Apr 2021 17:19:48 +0300 Subject: [PATCH 5/6] delete manually cleaning testData --- src/runner/JestRunner.ts | 3 +-- src/runner/TestRunner.ts | 3 +-- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/src/runner/JestRunner.ts b/src/runner/JestRunner.ts index 1ded8fc..881312f 100644 --- a/src/runner/JestRunner.ts +++ b/src/runner/JestRunner.ts @@ -1,5 +1,5 @@ import { Config } from "@jest/types"; -import { resetTestData, ExecuteWithScope, types as BrsTypes } from "brs"; +import { ExecuteWithScope, types as BrsTypes } from "brs"; import { JestReporter } from "../reporter/JestReporter"; import { TestRunner } from "./TestRunner"; @@ -33,7 +33,6 @@ export class JestRunner extends TestRunner { testFiles.forEach((filename, index) => { this.reporter.onFileStart(filename); try { - resetTestData(); execute([filename], [executeArgs]); } catch (reason) { this.reporter.onFileExecError(filename, index, reason); diff --git a/src/runner/TestRunner.ts b/src/runner/TestRunner.ts index 336cf9b..8c52707 100644 --- a/src/runner/TestRunner.ts +++ b/src/runner/TestRunner.ts @@ -1,5 +1,5 @@ import * as path from "path"; -import { resetTestData, types as BrsTypes, ExecuteWithScope } from "brs"; +import { types as BrsTypes, ExecuteWithScope } from "brs"; import { formatInterpreterError } from "../util"; export class TestRunner { @@ -41,7 +41,6 @@ export class TestRunner { // Set the index so that our TAP reporting is correct. executeArgs.elements.set("index", new BrsTypes.Int32(index)); try { - resetTestData(); execute([filename], [executeArgs]); } catch (e) { console.error( From 93b7cdb07b6627f3ceef0827bc815dae5e4d0cb7 Mon Sep 17 00:00:00 2001 From: Vasyl Martynych Date: Tue, 18 May 2021 21:09:36 +0300 Subject: [PATCH 6/6] remove UT --- test/e2e/before-after/before-after.test.js | 6 ++---- test/e2e/before-after/mixed/tests/01-nested.test.brs | 10 ---------- .../before-after/mixed/tests/02-single-level.test.brs | 10 ---------- 3 files changed, 2 insertions(+), 24 deletions(-) diff --git a/test/e2e/before-after/before-after.test.js b/test/e2e/before-after/before-after.test.js index ec9a45a..8683a87 100644 --- a/test/e2e/before-after/before-after.test.js +++ b/test/e2e/before-after/before-after.test.js @@ -72,8 +72,8 @@ describe("before-after", () => { expect(results.stats).toMatchObject({ suites: 4, - tests: 14, - passes: 11, + tests: 12, + passes: 9, pending: 3, failures: 0, }); @@ -85,11 +85,9 @@ describe("before-after", () => { { fullTitle: "nested root case 1" }, { fullTitle: "nested root case 2" }, { fullTitle: "nested root case 3" }, - { fullTitle: "nested root check _brs_.testData" }, { fullTitle: "single-level root case 1" }, { fullTitle: "single-level root case 2" }, { fullTitle: "single-level root case 3" }, - { fullTitle: "single-level root check _brs_.testData" }, ]); }); }); diff --git a/test/e2e/before-after/mixed/tests/01-nested.test.brs b/test/e2e/before-after/mixed/tests/01-nested.test.brs index b28514b..5f0553c 100644 --- a/test/e2e/before-after/mixed/tests/01-nested.test.brs +++ b/test/e2e/before-after/mixed/tests/01-nested.test.brs @@ -31,16 +31,6 @@ function main(args as object) as object m.assert.equal(m.counterB, 11, "counterB must be incremented for each test case") end sub) - m.it("check _brs_.testData", sub() - m.assert.isTrue(_brs_.testData <> invalid, "_brs_.testData should be presented") - m.assert.isTrue(_brs_.testData.count() = 0, "by default _brs_.testData should be equal to {}") - - ' change value to check whether it clears between different test files - _brs_.testData = { - ctx: "file 1" - } - end sub) - m.describe("suite 1", sub() m.addContext({ counterC: 0 diff --git a/test/e2e/before-after/mixed/tests/02-single-level.test.brs b/test/e2e/before-after/mixed/tests/02-single-level.test.brs index df3635b..cece314 100644 --- a/test/e2e/before-after/mixed/tests/02-single-level.test.brs +++ b/test/e2e/before-after/mixed/tests/02-single-level.test.brs @@ -37,15 +37,5 @@ function main(args as object) as object m.assert.isInvalid(m.counterB, "afterEach state must not spread to sibling suites") m.assert.equal(m.counterA, 5, "counterA must be incremented for each test case") end sub) - - m.it("check _brs_.testData", sub() - m.assert.isTrue(_brs_.testData <> invalid, "_brs_.testData should be presented") - m.assert.isTrue(_brs_.testData.count() = 0, "by default _brs_.testData should be equal to {}") - - ' change value to check whether it clears between different test files - _brs_.testData = { - ctx: "file 1" - } - end sub) end sub) end function