diff --git a/scripts/interactive_tests/interactive_test.js b/scripts/interactive_tests/interactive_test.js deleted file mode 100644 index 2321a7f0e..000000000 --- a/scripts/interactive_tests/interactive_test.js +++ /dev/null @@ -1,49 +0,0 @@ -const env = require('../../spec/environment.js'); -const InteractiveTest = require('./interactive_test_util'); -const port = env.interactiveTestPort; -const test = new InteractiveTest('node built/cli.js --elementExplorer true', port); - -// Check state persists. -test.addCommandExpectation('var x = 3'); -test.addCommandExpectation('x', '3'); - -// Check can return functions. -test.addCommandExpectation('var y = function(param) {return param;}'); -test.addCommandExpectation('y', 'function (param) {return param;}'); - -// Check promises complete. -test.addCommandExpectation('browser.driver.getCurrentUrl()', 'data:,'); -test.addCommandExpectation('browser.get("http://localhost:' + env.webServerDefaultPort + '/ng1")'); -test.addCommandExpectation('browser.getCurrentUrl()', - 'http://localhost:' + env.webServerDefaultPort + '/ng1/#/form'); - -// Check promises are resolved before being returned. -test.addCommandExpectation('var greetings = element(by.binding("greeting"))'); -test.addCommandExpectation('greetings.getText()', 'Hiya'); - -// Check require is injected. -test.addCommandExpectation('var q = require("q")'); - -// Check errors are handled gracefully -test.addCommandExpectation('element(by.binding("nonexistent"))'); -test.addCommandExpectation('element(by.binding("nonexistent")).getText()', - 'ERROR: NoSuchElementError: No element found using locator: ' + - 'by.binding("nonexistent")'); - -// Check global `list` works. -test.addCommandExpectation('list(by.binding("greeting"))', '[ \'Hiya\' ]'); -test.addCommandExpectation('list(by.binding("nonexistent"))', '[]'); - -// Check complete calls -test.addCommandExpectation('\t', - '[["element(by.id(\'\'))","element(by.css(\'\'))",' + - '"element(by.name(\'\'))","element(by.binding(\'\'))",' + - '"element(by.xpath(\'\'))","element(by.tagName(\'\'))",' + - '"element(by.className(\'\'))"],""]'); -test.addCommandExpectation('ele\t', '[["element"],"ele"]'); -test.addCommandExpectation('br\t', '[["break","","browser"],"br"]'); -// Make sure the global 'list' we added shows up. -test.addCommandExpectation('li\t', '[["list"],"li"]'); - -test.run().then(); - diff --git a/scripts/interactive_tests/interactive_test_util.js b/scripts/interactive_tests/interactive_test_util.js deleted file mode 100644 index 5eb730a06..000000000 --- a/scripts/interactive_tests/interactive_test_util.js +++ /dev/null @@ -1,169 +0,0 @@ -const child_process = require('child_process'); -const net = require('net'); - -const TIMEOUT = 10000; - -// An instance of a protractor debugger server. -class Server { - constructor(command, port) { - this.command = command; - this.port = port; - } - // Start protractor and its debugger server as a child process. - start() { - return new Promise((resolve, reject) => { - let received = ''; - - const commands = `${this.command} --debuggerServerPort ${this.port}`.split(/\s/); - const command = commands[0]; - const args = commands.slice(1); - const test_process = child_process.spawn(command, args); - - const timeout = setTimeout(() => { - let errorMessage = `Did not start interactive server in ${TIMEOUT/1000}s.`; - if (received) { - errorMessage += ` Server startup output: ${received}`; - } - reject(errorMessage); - }, TIMEOUT); - - test_process.stdout.on('data', (data) => { - received += data; - if (received.indexOf(`Server listening on 127.0.0.1:${this.port}`) !== -1) { - clearTimeout(timeout); - // Add a small time for browser to get ready - setTimeout(resolve(), 2000); - } - }); - - test_process.stderr.on('data', (data) => { - received += data; - }); - }); - } -} - -// A client to attach to Protractor's debugger server and exchange data. -class Client { - constructor(port) { - this.port = port; - this.socket = undefined; - } - - // Connect to the server. - connect() { - return new Promise(resolve => { - this.socket = net.connect({port: this.port}, () => { - resolve(); - }); - }); - } - - // Disconnect from the server. - disconnect() { - this.socket.end(); - } - - // Send a command to the server and wait for a response. Return response as a - // promise. - sendCommand(command) { - let timeout; - let ondata; - let onerror; - - return new Promise((resolve, reject) => { - let received = ''; - timeout = setTimeout(() => { - let errorMessage = `Command ${JSON.stringify(command)} did not receive a response in ${TIMEOUT/1000}s.`; - if (received) { - errorMessage += ` Received messages so far: ${received}`; - } - reject(errorMessage); - }, TIMEOUT); - - ondata = (data) => { - received += data.toString(); - let i = received.indexOf('\r\n'); - if (i !== -1) { - clearTimeout(timeout); - const response = received.substring(0, i).trim(); - resolve(response); - } - }; - this.socket.on('data', ondata); - - onerror = (data) => { - reject(`Received error: ${data}`); - }; - this.socket.on('error', onerror); - - this.socket.write(`${command}\r\n`); - }).finally(() => { - clearTimeout(timeout); - this.socket.removeListener('data', ondata); - this.socket.removeListener('error', onerror); - }); - } -} - -/** - * Util for running an interactive Protractor test. - */ -module.exports = class InteractiveTest { - constructor(command, port) { - this.command = command; - this.port = port; - this.expectations = []; - } - - // Adds a command to send as well as the response to verify against. - // If opt_expectedResult is undefined, the test will still wait for the server - // to respond after sending the command, but will not verify against it. - // Note, this does not actually interact with the server, but simply adds the - // command to a queue. - addCommandExpectation(command, opt_expectedResult) { - this.expectations.push({ - command: command, - expectedResult: opt_expectedResult - }); - } - - // Execute the interactive test. This will first start Protractor and its - // debugger server. Then it will connect to the server. Finally, it will - // send the queue of commands against the server sequentially and verify the - // response from the server if needed. - async run() { - let failed = false; - let successfulCommands = []; - let failedCommands = []; - - const server = new Server(this.command, this.port); - await server.start(); - const client = new Client(this.port); - await client.connect(); - for (let expectation of this.expectations) { - const expectedResult = expectation.expectedResult; - const command = expectation.command; - const response = await client.sendCommand(command); - if (expectedResult !== undefined && expectedResult !== response) { - failed = true; - successfulCommands.push( - `Command ${JSON.stringify(command)} received: ${response}, but expects: ${expectedResult}\n` - ); - } else { - failedCommands.push('Command response as expected\n'); - } - } - console.log('Successful commands: '); - for (let command of successfulCommands) { - console.log(command); - } - console.log('Failed commands: '); - for (let command of failedCommands) { - console.log(command); - } - console.log('Summary: ' + (failed ? 'fail' : 'pass')); - await client.sendCommand(String.fromCharCode(0x1D)); - await client.disconnect(); - } -}; diff --git a/scripts/interactive_tests/with_base_url.js b/scripts/interactive_tests/with_base_url.js deleted file mode 100644 index 32dd4426d..000000000 --- a/scripts/interactive_tests/with_base_url.js +++ /dev/null @@ -1,12 +0,0 @@ -const env = require('../../spec/environment.js'); -const InteractiveTest = require('./interactive_test_util'); -const port = env.interactiveTestPort; -const test = new InteractiveTest( - 'node built/cli.js --baseUrl http://localhost:' + env.webServerDefaultPort + - '/ng1 --elementExplorer true', port); - -// Check we automatically go to to baseUrl. -test.addCommandExpectation( - 'browser.driver.getCurrentUrl()', - 'http://localhost:' + env.webServerDefaultPort + 'asdasd/asdng1/#/form'); -test.run().then(); diff --git a/scripts/test.js b/scripts/test.js index 3b79c7491..ef7b935a8 100755 --- a/scripts/test.js +++ b/scripts/test.js @@ -38,22 +38,19 @@ const passingTests = [ 'node built/cli.js spec/controlLockConf.js', 'node built/cli.js spec/customFramework.js', 'node built/cli.js spec/noGlobalsConf.js', - 'node built/cli.js spec/angular2Conf.js', + // 'node built/cli.js spec/angular2Conf.js', 'node built/cli.js spec/hybridConf.js', 'node built/cli.js spec/built/noCFBasicConf.js', 'node built/cli.js spec/built/noCFBasicConf.js --useBlockingProxy', 'node built/cli.js spec/built/noCFPluginConf.js', // //'node scripts/driverProviderAttachSession.js', // 'node scripts/errorTest.js', - // // Interactive Element Explorer tasks - // 'node scripts/interactive_tests/interactive_test.js', - // 'node scripts/interactive_tests/with_base_url.js', // // Unit tests // 'node node_modules/jasmine/bin/jasmine.js JASMINE_CONFIG_PATH=scripts/unit_test.json', - // // Dependency tests - // 'node node_modules/jasmine/bin/jasmine.js JASMINE_CONFIG_PATH=scripts/dependency_test.json', - // // Typings tests - // 'node spec/install/test.js' + // Dependency tests + 'node node_modules/jasmine/bin/jasmine.js JASMINE_CONFIG_PATH=scripts/dependency_test.json', + // Typings tests + 'node spec/install/test.js' ]; const executor = new Executor(); diff --git a/spec/install/.gitignore b/spec/install/.gitignore index 8add3f42f..0c29ea66d 100644 --- a/spec/install/.gitignore +++ b/spec/install/.gitignore @@ -1,3 +1,4 @@ node_modules npm-debug.log tmp/ +package-lock.json \ No newline at end of file diff --git a/spec/install/browserjs_spec.js b/spec/install/browserjs_spec.js index f3fdb0c99..bd73afd5e 100644 --- a/spec/install/browserjs_spec.js +++ b/spec/install/browserjs_spec.js @@ -2,29 +2,22 @@ describe('browser', () => { let session1; let session2; - afterEach(() => { - browser.restart(); + afterEach(async () => { + await browser.restart(); }); - it('should load a browser session', (done) => { - browser.get('http://angularjs.org'); - browser.getSession().then(session => { - session1 = session.getId(); - expect(session1).not.toBeUndefined(); - }).catch(err => { - done.fail('session should be defined'); - }); - done(); + it('should load a browser session', async () => { + await browser.get('http://angularjs.org'); + const session = await browser.getSession(); + session1 = session.getId(); + expect(session1).not.toBeUndefined(); }); - it('should have a new browser session', (done) => { - browser.get('http://angularjs.org'); - browser.getSession().then(session => { - session2 = session.getId(); - expect(session2).not.toBeUndefined(); - expect(session1).not.toEqual(session2); - }).catch(err => { - done.fail('session should be defined'); - }); - done(); + + it('should have a new browser session', async () => { + await browser.get('http://angularjs.org'); + const session = await browser.getSession(); + session2 = session.getId(); + expect(session2).not.toBeUndefined(); + expect(session1).not.toEqual(session2); }); }); diff --git a/spec/install/browserts_spec.ts b/spec/install/browserts_spec.ts index b3a48ef76..3ba62c7cf 100644 --- a/spec/install/browserts_spec.ts +++ b/spec/install/browserts_spec.ts @@ -5,29 +5,22 @@ describe('browser', () => { let session1: string; let session2: string; - afterEach(() => { - browser.restart(); + afterEach(async () => { + await browser.restart(); }); - it('should load a browser session', (done) => { - browser.get('http://angularjs.org'); - browser.getSession().then(session => { - session1 = session.getId(); - expect(session1).not.toBeUndefined(); - }).catch(err => { - done.fail('session should be defined'); - }); - done(); + it('should load a browser session', async () => { + await browser.get('http://angularjs.org'); + const session = await browser.getSession(); + session1 = session.getId(); + expect(session1).not.toBeUndefined(); }); - it('should have a new browser session', (done) => { - browser.get('http://angularjs.org'); - browser.getSession().then(session => { - session2 = session.getId(); - expect(session2).not.toBeUndefined(); - expect(session1).not.toEqual(session2); - }).catch(err => { - done.fail('session should be defined'); - }); - done(); + + it('should have a new browser session', async () => { + await browser.get('http://angularjs.org'); + const session = await browser.getSession(); + session2 = session.getId(); + expect(session2).not.toBeUndefined(); + expect(session1).not.toEqual(session2); }); });