Skip to content

Commit

Permalink
move to modules, but break mocha
Browse files Browse the repository at this point in the history
  • Loading branch information
BeksOmega committed Mar 3, 2022
1 parent 1f8eb8f commit 220d7bb
Show file tree
Hide file tree
Showing 16 changed files with 94 additions and 144 deletions.
26 changes: 13 additions & 13 deletions tests/deps.mocha.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions tests/mocha/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
{
"parserOptions": {
"sourceType": "module"
},
"env": {
"browser": true,
"mocha": true
Expand Down
6 changes: 6 additions & 0 deletions tests/mocha/astnode_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ const {sharedTestSetup, sharedTestTeardown, workspaceTeardown} = goog.require('B


suite('ASTNode', function() {
console.log('1/a');
setup(function() {
sharedTestSetup.call(this);
Blockly.defineBlocksWithJsonArray([{
Expand Down Expand Up @@ -100,7 +101,9 @@ suite('ASTNode', function() {
});

suite('HelperFunctions', function() {
console.log('2');
test('findNextForInput_', function() {
console.log('3');
const input = this.blocks.statementInput1.inputList[0];
const input2 = this.blocks.statementInput1.inputList[1];
const connection = input.connection;
Expand Down Expand Up @@ -169,6 +172,7 @@ suite('ASTNode', function() {
});

suite('NavigationFunctions', function() {
console.log('b');
setup(function() {
Blockly.defineBlocksWithJsonArray([{
"type": "top_connection",
Expand Down Expand Up @@ -319,7 +323,9 @@ suite('ASTNode', function() {
workspaceTeardown.call(this, this.singleBlockWorkspace);
});

console.log('c');
test('fromPreviousToBlock', function() {
console.log('d');
const prevConnection = this.blocks.statementInput1.previousConnection;
const node = ASTNode.createConnectionNode(prevConnection);
const nextNode = node.next();
Expand Down
23 changes: 8 additions & 15 deletions tests/mocha/test_helpers/block_definitions.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,19 @@
* SPDX-License-Identifier: Apache-2.0
*/

goog.module('Blockly.test.helpers.blockDefinitions');
goog.declareModuleId('Blockly.test.helpers.blockDefinitions');


function defineStackBlock(name = 'stack_block') {
export function defineStackBlock(name = 'stack_block') {
Blockly.defineBlocksWithJsonArray([{
"type": name,
"message0": "",
"previousStatement": null,
"nextStatement": null,
}]);
}
exports.defineStackBlock = defineStackBlock;

function defineRowBlock(name = 'row_block') {
export function defineRowBlock(name = 'row_block') {
Blockly.defineBlocksWithJsonArray([{
"type": name,
"message0": "%1",
Expand All @@ -30,9 +29,8 @@ function defineRowBlock(name = 'row_block') {
"output": null,
}]);
}
exports.defineRowBlock = defineRowBlock;

function defineStatementBlock(name = 'statement_block') {
export function defineStatementBlock(name = 'statement_block') {
Blockly.defineBlocksWithJsonArray([{
"type": name,
"message0": "%1",
Expand All @@ -49,9 +47,8 @@ function defineStatementBlock(name = 'statement_block') {
"helpUrl": "",
}]);
}
exports.defineStatementBlock = defineStatementBlock;

function defineBasicBlockWithField(name = 'test_field_block') {
export function defineBasicBlockWithField(name = 'test_field_block') {
Blockly.defineBlocksWithJsonArray([{
"type": name,
"message0": "%1",
Expand All @@ -64,9 +61,8 @@ function defineBasicBlockWithField(name = 'test_field_block') {
"output": null,
}]);
}
exports.defineBasicBlockWithField = defineBasicBlockWithField;

function defineMutatorBlocks() {
export function defineMutatorBlocks() {
Blockly.defineBlocksWithJsonArray([
{
'type': 'xml_block',
Expand Down Expand Up @@ -158,9 +154,8 @@ function defineMutatorBlocks() {
};
Blockly.Extensions.registerMutator('jso_mutator', jsoMutator);
}
exports.defineMutatorBlocks = defineMutatorBlocks;

function createTestBlock() {
export function createTestBlock() {
return {
'id': 'test',
'rendered': false,
Expand All @@ -174,12 +169,10 @@ function createTestBlock() {
'updateVarName': Blockly.Block.prototype.updateVarName,
};
}
exports.createTestBlock = createTestBlock;

function createRenderedBlock(workspaceSvg, type) {
export function createRenderedBlock(workspaceSvg, type) {
const block = workspaceSvg.newBlock(type);
block.initSvg();
block.render();
return block;
}
exports.createRenderedBlock = createRenderedBlock;
11 changes: 4 additions & 7 deletions tests/mocha/test_helpers/code_generation.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* SPDX-License-Identifier: Apache-2.0
*/

goog.module('Blockly.test.helpers.codeGeneration');
goog.declareModuleId('Blockly.test.helpers.codeGeneration');

const {runTestSuites} = goog.require('Blockly.test.helpers.common');

Expand All @@ -15,7 +15,7 @@ const {runTestSuites} = goog.require('Blockly.test.helpers.common');
* @implements {TestCase}
* @record
*/
class CodeGenerationTestCase {
export class CodeGenerationTestCase {
/**
* Class for a code generation test case.
*/
Expand Down Expand Up @@ -43,14 +43,13 @@ class CodeGenerationTestCase {
*/
createBlock(workspace) {}
}
exports.CodeGenerationTestCase = CodeGenerationTestCase;

/**
* Code generation test suite.
* @extends {TestSuite<CodeGenerationTestCase, CodeGenerationTestSuite>}
* @record
*/
class CodeGenerationTestSuite {
export class CodeGenerationTestSuite {
/**
* Class for a code generation test suite.
*/
Expand All @@ -61,7 +60,6 @@ class CodeGenerationTestSuite {
this.generator;
}
}
exports.CodeGenerationTestSuite = CodeGenerationTestSuite;

/**
* Returns mocha test callback for code generation based on provided
Expand Down Expand Up @@ -102,7 +100,7 @@ const createCodeGenerationTestFn_ = (generator) => {
* Runs blockToCode test suites.
* @param {!Array<!CodeGenerationTestSuite>} testSuites The test suites to run.
*/
const runCodeGenerationTestSuites = (testSuites) => {
export const runCodeGenerationTestSuites = (testSuites) => {
/**
* Creates function used to generate mocha test callback.
* @param {!CodeGenerationTestSuite} suiteInfo The test suite information.
Expand All @@ -115,4 +113,3 @@ const runCodeGenerationTestSuites = (testSuites) => {

runTestSuites(testSuites, createTestFn);
};
exports.runCodeGenerationTestSuites = runCodeGenerationTestSuites;
14 changes: 5 additions & 9 deletions tests/mocha/test_helpers/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@
* SPDX-License-Identifier: Apache-2.0
*/

goog.module('Blockly.test.helpers.common');
goog.declareModuleId('Blockly.test.helpers.common');

/**
* Test case configuration.
* @record
*/
class TestCase {
export class TestCase {
/**
* Class for a test case configuration.
*/
Expand All @@ -31,15 +31,14 @@ class TestCase {
this.only;
}
}
exports.TestCase = TestCase;

/**
* Test suite configuration.
* @record
* @template {TestCase} T
* @template {TestSuite} U
*/
class TestSuite {
export class TestSuite {
/**
* Class for a test suite configuration.
*/
Expand Down Expand Up @@ -68,7 +67,6 @@ class TestSuite {
this.only;
}
}
exports.TestSuite = TestSuite;

/**
* Runs provided test cases.
Expand All @@ -77,14 +75,13 @@ exports.TestSuite = TestSuite;
* @param {function(T):Function} createTestCallback Creates test
* callback using given test case.
*/
function runTestCases(testCases, createTestCallback) {
export function runTestCases(testCases, createTestCallback) {
testCases.forEach((testCase) => {
let testCall = (testCase.skip ? test.skip : test);
testCall = (testCase.only ? test.only : testCall);
testCall(testCase.title, createTestCallback(testCase));
});
}
exports.runTestCases = runTestCases;

/**
* Runs provided test suite.
Expand All @@ -95,7 +92,7 @@ exports.runTestCases = runTestCases;
* } createTestCaseCallback Creates test case callback using given test
* suite.
*/
function runTestSuites(testSuites, createTestCaseCallback) {
export function runTestSuites(testSuites, createTestCaseCallback) {
testSuites.forEach((testSuite) => {
let suiteCall = (testSuite.skip ? suite.skip : suite);
suiteCall = (testSuite.only ? suite.only : suiteCall);
Expand All @@ -109,4 +106,3 @@ function runTestSuites(testSuites, createTestCaseCallback) {
});
});
}
exports.runTestSuites = runTestSuites;
17 changes: 6 additions & 11 deletions tests/mocha/test_helpers/events.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* SPDX-License-Identifier: Apache-2.0
*/

goog.module('Blockly.test.helpers.events');
goog.declareModuleId('Blockly.test.helpers.events');


/**
Expand All @@ -13,10 +13,9 @@ goog.module('Blockly.test.helpers.events');
* calls on.
* @return {!SinonSpy} The created spy.
*/
function createFireChangeListenerSpy(workspace) {
export function createFireChangeListenerSpy(workspace) {
return sinon.spy(workspace, 'fireChangeListener');
}
exports.createFireChangeListenerSpy = createFireChangeListenerSpy;

/**
* Asserts whether the given xml property has the expected property.
Expand Down Expand Up @@ -75,7 +74,7 @@ function isXmlProperty_(key) {
* @param {boolean=} [isUiEvent=false] Whether the event is a UI event.
* @param {string=} message Optional message to prepend assert messages.
*/
function assertEventEquals(event, expectedType,
export function assertEventEquals(event, expectedType,
expectedWorkspaceId, expectedBlockId, expectedProperties, isUiEvent = false, message) {
let prependMessage = message ? message + ' ' : '';
prependMessage += 'Event fired ';
Expand Down Expand Up @@ -107,7 +106,6 @@ function assertEventEquals(event, expectedType,
chai.assert.isFalse(event.isUiEvent);
}
}
exports.assertEventEquals = assertEventEquals;

/**
* Asserts that an event with the given values was fired.
Expand All @@ -119,7 +117,7 @@ exports.assertEventEquals = assertEventEquals;
* @param {string} expectedWorkspaceId Expected workspace id of event fired.
* @param {?string=} expectedBlockId Expected block id of event fired.
*/
function assertEventFired(spy, instanceType, expectedProperties,
export function assertEventFired(spy, instanceType, expectedProperties,
expectedWorkspaceId, expectedBlockId) {
expectedProperties = Object.assign({
workspaceId: expectedWorkspaceId,
Expand All @@ -129,7 +127,6 @@ function assertEventFired(spy, instanceType, expectedProperties,
sinon.match.instanceOf(instanceType).and(sinon.match(expectedProperties));
sinon.assert.calledWith(spy, expectedEvent);
}
exports.assertEventFired = assertEventFired;

/**
* Asserts that an event with the given values was not fired.
Expand All @@ -141,7 +138,7 @@ exports.assertEventFired = assertEventFired;
* @param {string=} expectedWorkspaceId Expected workspace id of event fired.
* @param {?string=} expectedBlockId Expected block id of event fired.
*/
function assertEventNotFired(spy, instanceType, expectedProperties,
export function assertEventNotFired(spy, instanceType, expectedProperties,
expectedWorkspaceId, expectedBlockId) {
expectedProperties.type = instanceType.prototype.type;
if (expectedWorkspaceId !== undefined) {
Expand All @@ -154,7 +151,6 @@ function assertEventNotFired(spy, instanceType, expectedProperties,
sinon.match.instanceOf(instanceType).and(sinon.match(expectedProperties));
sinon.assert.neverCalledWith(spy, expectedEvent);
}
exports.assertEventNotFired = assertEventNotFired;

/**
* Filters out xml properties from given object based on key.
Expand Down Expand Up @@ -189,7 +185,7 @@ function splitByXmlProperties_(properties) {
* @param {string} expectedWorkspaceId Expected workspace id of event fired.
* @param {?string=} expectedBlockId Expected block id of event fired.
*/
function assertNthCallEventArgEquals(spy, n, instanceType, expectedProperties,
export function assertNthCallEventArgEquals(spy, n, instanceType, expectedProperties,
expectedWorkspaceId, expectedBlockId) {
const nthCall = spy.getCall(n);
const splitProperties = splitByXmlProperties_(expectedProperties);
Expand All @@ -201,4 +197,3 @@ function assertNthCallEventArgEquals(spy, n, instanceType, expectedProperties,
const eventArg = nthCall.firstArg;
assertXmlProperties_(eventArg, xmlProperties);
}
exports.assertNthCallEventArgEquals = assertNthCallEventArgEquals;
Loading

0 comments on commit 220d7bb

Please sign in to comment.