From 459e4b645dadbc5e0d0862de4645cfebaa166786 Mon Sep 17 00:00:00 2001 From: Greg Thornton Date: Sat, 1 Aug 2015 10:22:40 -0500 Subject: [PATCH] Add test interface option --- lib/Recorder.js | 111 +++++++++++++++++++++++++++-------- lib/RecorderProxy.js | 17 ++++++ lib/panel.html | 9 +++ tests/data/output/bdd.txt | 9 +++ tests/data/output/object.txt | 10 ++++ tests/data/output/tdd.txt | 9 +++ tests/unit/Recorder.js | 30 +++++++++- 7 files changed, 170 insertions(+), 25 deletions(-) create mode 100644 tests/data/output/bdd.txt create mode 100644 tests/data/output/object.txt create mode 100644 tests/data/output/tdd.txt diff --git a/lib/Recorder.js b/lib/Recorder.js index b90ae64..174dba1 100644 --- a/lib/Recorder.js +++ b/lib/Recorder.js @@ -182,26 +182,73 @@ })(); var TEMPLATES = { - suiteOpen: [ - 'define(function (require) {', - ' var tdd = require(\'intern!tdd\');', - ' tdd.suite(\'recorder-generated suite\', function () {', - '' - ].join('\n'), - suiteClose: [ - ' });', - '});', - '' - ].join('\n'), - testOpen: [ - ' tdd.test(\'$NAME\', function () {', - ' return this.remote' - ].join('\n'), - testClose: [ - ';', - ' });', - '' - ].join('\n') + object: { + suiteOpen: [ + 'define(function (require) {', + ' var registerSuite = require(\'intern!object\');', + ' registerSuite({', + ' name: \'recorder-generated suite\',', + '' + ].join('\n'), + suiteClose: [ + ' });', + '});', + '' + ].join('\n'), + testOpen: [ + ' \'$NAME\': function () {', + ' return this.remote' + ].join('\n'), + testClose: [ + ';', + ' }', + '' + ].join('\n') + }, + tdd: { + suiteOpen: [ + 'define(function (require) {', + ' var tdd = require(\'intern!tdd\');', + ' tdd.suite(\'recorder-generated suite\', function () {', + '' + ].join('\n'), + suiteClose: [ + ' });', + '});', + '' + ].join('\n'), + testOpen: [ + ' tdd.test(\'$NAME\', function () {', + ' return this.remote' + ].join('\n'), + testClose: [ + ';', + ' });', + '' + ].join('\n') + }, + bdd: { + suiteOpen: [ + 'define(function (require) {', + ' var bdd = require(\'intern!bdd\');', + ' bdd.describe(\'recorder-generated suite\', function () {', + '' + ].join('\n'), + suiteClose: [ + ' });', + '});', + '' + ].join('\n'), + testOpen: [ + ' bdd.it(\'$NAME\', function () {', + ' return this.remote' + ].join('\n'), + testClose: [ + ';', + ' });', + '' + ].join('\n') + } }; function Recorder(chrome, storage) { @@ -217,6 +264,7 @@ this.storage = storage; this.hotkeys = JSON.parse(storage.getItem('intern.hotkeys')) || this._getDefaultHotkeys(); this.strategy = storage.getItem('intern.strategy') || 'xpath'; + this.testInterface = storage.getItem('intern.interface') || 'tdd'; this.findDisplayed = storage.getItem('intern.findDisplayed') || false; this._initializeScript(); @@ -259,6 +307,8 @@ strategy: null, + testInterface: null, + tabId: null, clear: function () { @@ -727,6 +777,7 @@ this._port.send('setScript', [ this._script ]); this._port.send('setRecording', [ this.recording ]); this._port.send('setStrategy', [ this.strategy ]); + this._port.send('setInterface', [ this.testInterface ]); for (var hotkeyId in this.hotkeys) { this._port.send('setHotkey', [ hotkeyId, this.hotkeys[hotkeyId] ]); @@ -734,17 +785,18 @@ }, _renderScriptTree: function () { - var script = TEMPLATES.suiteOpen; + var template = TEMPLATES[this.testInterface]; + var script = template.suiteOpen; this._scriptTree.forEach(function (test) { - script += TEMPLATES.testOpen.replace('$NAME', test.name); + script += template.testOpen.replace('$NAME', test.name); test.commands.forEach(function (command) { script += command.text; }); - script += TEMPLATES.testClose; + script += template.testClose; }); - script += TEMPLATES.suiteClose; + script += template.suiteClose; this.setScript(script); }, @@ -788,6 +840,17 @@ this._contentPort.send('setStrategy', [ value ]); }, + setInterface: function (value) { + if (['object', 'tdd', 'bdd'].indexOf(value) < 0) { + throw new Error('Invalid test interface "' + value + '"'); + } + + this.storage.setItem('intern.interface', value); + this.testInterface = value; + this._port.send('setInteface', [ value ]); + this._renderScriptTree(); + }, + setTabId: function (tabId) { if (tabId && this.tabId !== tabId) { this.tabId = tabId; diff --git a/lib/RecorderProxy.js b/lib/RecorderProxy.js index fb10471..625e249 100644 --- a/lib/RecorderProxy.js +++ b/lib/RecorderProxy.js @@ -215,6 +215,17 @@ input.onchange = function (event) { self.send('setFindDisplayed', [ event.target.checked ]); }; + + input = document.getElementById('option-interface'); + + /* istanbul ignore if: the recorder is broken if this ever happens */ + if (!input) { + throw new Error('Panel is missing input for option "interface"'); + } + + input.onchange = function (event) { + self.send('setInterface', [ event.target.value ]); + }; }, _initializePort: function () { @@ -313,6 +324,12 @@ } }, + setInterface: function (value) { + if (this.contentWindow) { + this.contentWindow.document.getElementById('option-interface').value = value; + } + }, + _show: function (contentWindow) { if (this.contentWindow !== contentWindow) { this.contentWindow = contentWindow; diff --git a/lib/panel.html b/lib/panel.html index 3b56088..52c61d6 100644 --- a/lib/panel.html +++ b/lib/panel.html @@ -102,6 +102,15 @@ +
+ + +
+