From 6ea1964c1f9fa01bc9578b1a4adca339ec23846e Mon Sep 17 00:00:00 2001 From: "Jay.Udey" Date: Tue, 8 Aug 2017 09:13:31 -0500 Subject: [PATCH] allow web-compiler flag to be passed through dart_dev no message --- lib/src/tasks/test/cli.dart | 13 +++++++++-- test/integration/test_test.dart | 40 +++++++++++++++++++++++++++------ 2 files changed, 44 insertions(+), 9 deletions(-) diff --git a/lib/src/tasks/test/cli.dart b/lib/src/tasks/test/cli.dart index 1de17b38..db30bfb7 100644 --- a/lib/src/tasks/test/cli.dart +++ b/lib/src/tasks/test/cli.dart @@ -61,7 +61,9 @@ class TestCli extends TaskCli { ..addOption('name', abbr: 'n', help: - 'A substring of the name of the test to run.\nRegular expression syntax is supported.'); + 'A substring of the name of the test to run.\nRegular expression syntax is supported.') + ..addOption('web-compiler', + abbr: 'w', help: ' The JavaScript compiler to use to serve the tests.'); final String command = 'test'; @@ -118,6 +120,8 @@ class TestCli extends TaskCli { // CLI user can filter tests by name. bool testNamed = parsedArgs['name'] != null; + bool compilerSpecified = parsedArgs['web-compiler'] != null; + if (!individualTestsSpecified && !unit && !integration && !functional) { return new CliResult.fail( 'No tests were selected. Include at least one of --unit, ' @@ -169,8 +173,13 @@ class TestCli extends TaskCli { if (!isPubServeRunning) { // Start `pub serve` on the `test` directory + var additionalArgs = ['test']; + if (compilerSpecified) { + additionalArgs.add('--web-compiler=${parsedArgs['web-compiler']}'); + } + pubServeTask = - startPubServe(port: pubServePort, additionalArgs: ['test']); + startPubServe(port: pubServePort, additionalArgs: additionalArgs); var startupLogFinished = new Completer(); reporter.logGroup(pubServeTask.command, diff --git a/test/integration/test_test.dart b/test/integration/test_test.dart index 2624a3f3..314187d7 100644 --- a/test/integration/test_test.dart +++ b/test/integration/test_test.dart @@ -38,7 +38,8 @@ Future runTests(String projectPath, List files, String testName: '', bool runCustomPubServe: false, - int pubServePort: 56090}) async { + int pubServePort: 56090, + String webCompiler}) async { await Process.run('pub', ['get'], workingDirectory: projectPath); List args = ['run', 'dart_dev', 'test', '--no-color']; @@ -77,24 +78,44 @@ Future runTests(String projectPath, } args.addAll(files ?? []); + + String webCompilerArg; + + if (webCompiler != null) { + webCompilerArg = '--web-compiler=${webCompiler}'; + args.add(webCompilerArg); + } + TaskProcess process = new TaskProcess('pub', args, workingDirectory: projectPath); + var numTestsRun = -1; + var webCompilerSpecified = false; + + process.stdout.listen((output) { + if (numTestsPassedPattern.hasMatch(output)) { + numTestsRun = + int.parse(numTestsPassedPattern.firstMatch(output).group(1)); + } + if (webCompiler != null && output.contains(webCompilerArg)) { + webCompilerSpecified = true; + } + }); + await process.done; if ((await process.exitCode) != 0) throw new TestFailure('Expected test to pass.'); - String lastLine = await process.stdout.last; - if (pubServeProcess != null) { pubServeProcess.kill(); } - var numTestsRun = -1; - if (numTestsPassedPattern.hasMatch(lastLine)) { - numTestsRun = - int.parse(numTestsPassedPattern.firstMatch(lastLine).group(1)); + if (webCompiler != null) { + expect(webCompilerSpecified, isTrue, + reason: + '$webCompiler was not approriately applied to the pub serve task'); } + return numTestsRun; } @@ -177,5 +198,10 @@ void main() { expect(runTests(projectWithPassingTests, testName: 'non-existent test'), throwsA(new isInstanceOf())); }); + + test('should allow you to specify a web-compiler', () async { + expect(await runTests(projectThatNeedsPubServe, webCompiler: 'dartdevc'), + equals(1)); + }); }); }