ngbp / spell-karma

An addon to add Karma unit testing support to the Warlock spell for managing client-side webapps.
MIT License
1 stars 1 forks source link

Flows depending on karma-single-run #4

Open Merott opened 10 years ago

Merott commented 10 years ago

It's been a while since I touched Warlock spells, so hopefully I'm not being stupid...

I'm writing a code-to-strip spell that is going to remove some debug/testing code from source files. It needs to run after karma-single-run has finished running. I've tried to make my flow _depend_ on karma-single-run but the code-to-strip flow appears to be skipped.

warlock.flow 'code-to-strip',
  source: [ '<%= paths.source %>/**/*' ]
  dest: '<%= paths.build %>'
  tasks: [ 'webapp-build' ]

  depends: [ 'flow::karma-single-run' ]

Warlock output for warlock -f flow::code-to-strip:

Starting task: clean::scripts-to-build
Starting task: flow::templates-to-build
Starting task: flow::coffee-to-build
Starting task: flow::vendor-scripts-to-build
Starting task: flow::scripts-to-build
Starting task: flow::karma-get-vendor
Starting task: flow::karma-single-run
Starting Karma Server.
PhantomJS 1.9.7 (Mac OS X): Executed 129 of 129 SUCCESS (0.326 secs / 0.316 secs)
>

The same does not happen if code-to-strip depends on some other flow like scripts-to-build so I'm guessing it has something to do with the special karma flow. And that it is something I do not understand (this very last statement took me a while to guess)

This might as well be an excuse for me to go back into Warlock mode.

joshdmiller commented 10 years ago

Hey @Merott - I've been pretty busy lately and have kind of dropped the ball with Warlock, something I hope to remedy.

I remember some cases with Grunt where Karma caused node to exit entirely, not completing remaining Grunt tasks. It had something to do with how Karma itself was stopping. Can you post the output with the flags --debug --verbose?

Merott commented 10 years ago

Hey. I know. I've been super busy too...

Here is the entire output with the flags on (definitely my longest code block to date!)

Merott-rMBP:Agent Merott$ warlock -f flow::code-to-strip --debug --verbose
Config found: /Users/Merott/Workspaces/Stashew/Agent/warlock.json
Config loaded.
package.json read from disk.
package.json loaded to `pkg`.
Loading all plugins...
Found warlock plugin warlock-spell-angular
Loading plugins from path '/Users/Merott/Workspaces/Stashew/Agent/node_modules/warlock-spell-angular/plugins'
Loading configurations for: /Users/Merott/Workspaces/Stashew/Agent/node_modules/warlock-spell-angular/plugins
Found warlock plugin warlock-spell-coffeescript
Loading plugins from path '/Users/Merott/Workspaces/Stashew/Agent/node_modules/warlock-spell-coffeescript/plugins'
Loading configurations for: /Users/Merott/Workspaces/Stashew/Agent/node_modules/warlock-spell-coffeescript/plugins
Found warlock plugin warlock-spell-karma
Loading plugins from path '/Users/Merott/Workspaces/Stashew/Agent/node_modules/warlock-spell-karma/plugins'
Loading configurations for: /Users/Merott/Workspaces/Stashew/Agent/node_modules/warlock-spell-karma/plugins
Found warlock plugin warlock-spell-less
Loading plugins from path '/Users/Merott/Workspaces/Stashew/Agent/node_modules/warlock-spell-less/plugins'
Loading configurations for: /Users/Merott/Workspaces/Stashew/Agent/node_modules/warlock-spell-less/plugins
Found warlock plugin warlock-spell-strip-code
Loading plugins from path '/Users/Merott/Workspaces/Stashew/Agent/node_modules/warlock-spell-strip-code/plugins'
Loading configurations for: /Users/Merott/Workspaces/Stashew/Agent/node_modules/warlock-spell-strip-code/plugins
Found warlock plugin warlock-spell-webapp
Loading plugins from path '/Users/Merott/Workspaces/Stashew/Agent/node_modules/warlock-spell-webapp/plugins'
Loading configurations for: /Users/Merott/Workspaces/Stashew/Agent/node_modules/warlock-spell-webapp/plugins
/Users/Merott/Workspaces/Stashew/Agent/node_modules/warlock-spell-angular-stubs/plugins doesn't export a function.
[scripts-to-compile] Added stream to queue: angular.annotate
[templates-to-build] Added stream to queue: angular.tplCache
[coffee-tests-to-lint] Added stream to queue: coffeescript-lint.lint
[coffee-tests-to-lint] Added stream to queue: coffeescript-lint.report
[coffee-tests-to-lint] Added stream to queue: coffeescript-lint.failOnError
[coffee-to-build] Added stream to queue: coffeescript-lint.lint
[coffee-to-build] Added stream to queue: coffeescript-lint.report
[coffee-to-build] Added stream to queue: coffeescript-lint.failOnError
[coffee-to-build] Added stream to queue: coffeescript-compile
[karma-single-run] Added stream to queue: karma-sort-vendor
[karma-single-run] Added stream to queue: karma.single-run
[karma-single-run] Added stream to queue: karma.reporter
[less-to-build] Added stream to queue: less-compile
[code-to-strip] Added stream to queue: strip-code
[html-to-build] Added stream to queue: webapp-html-template.build
[html-to-compile] Added stream to queue: webapp-html-template.compile
[scripts-to-lint] Added stream to queue: webapp-lintjs.lint
[scripts-to-lint] Added stream to queue: webapp-lintjs.reporter
[scripts-to-lint] Added stream to queue: webapp-lintjs.failOnError
[test-scripts-to-lint] Added stream to queue: webapp-lintjs.lint
[test-scripts-to-lint] Added stream to queue: webapp-lintjs.reporter
[test-scripts-to-lint] Added stream to queue: webapp-lintjs.failOnError
[scripts-to-build] Added stream to queue: webapp-sort
[scripts-to-build] Added stream to queue: webapp-tpl.scripts
[vendor-scripts-to-build] Added stream to queue: webapp-scripts.vendor
The flow 'scripts-to-compile' already exists, so I'm updating the options instead.
[scripts-to-compile] Added stream to queue: webapp-sort
[scripts-to-compile] Added stream to queue: webapp-concatjs
[scripts-to-compile] Added stream to queue: webapp-minjs
[scripts-to-compile] Added stream to queue: webapp-tpl.compile-scripts
[styles-to-build] Added stream to queue: webapp-lintcss.lint
[styles-to-build] Added stream to queue: webapp-lintcss.reporter
[styles-to-build] Added stream to queue: webapp-lintcss.failOnError
[styles-to-build] Added stream to queue: webapp-sort
[styles-to-build] Added stream to queue: webapp-tpl.styles
[vendor-styles-to-build] Added stream to queue: webapp-styles.vendor
[styles-to-compile] Added stream to queue: webapp-sort
[styles-to-compile] Added stream to queue: webapp-concatcss
[styles-to-compile] Added stream to queue: webapp-minjs
[styles-to-compile] Added stream to queue: webapp-tpl.compile-styles

Defined Flows

scripts-to-compile

Source  application/ngCore/build/scripts/**/*.js
Dest    application/ngCore/bin/assets
Streams webapp-sort, webapp-concatjs, angular.annotate, webapp-minjs, webapp-tpl.compile-scripts

templates-to-build

Source  application/ngCore/src/app/**/*.tpl.html
Dest    flow::scripts-to-build::95
Streams angular.tplCache

coffee-tests-to-lint

Source  application/ngCore/src/app/**/*.spec.coffee
Dest    none
Streams coffeescript-lint.lint, coffeescript-lint.report, coffeescript-lint.failOnError

coffee-to-build

Source  application/ngCore/src/app/**/*.coffee, application/ngCore/src/app/**/*.coffee.md, application/ngCore/src/app/**/*.coffee.markdown, !application/ngCore/src/app/**/*.spec.coffee, !application/ngCore/src/app/**/*.spec.coffee.md, !application/ngCore/src/app/**/*.spec.coffee.markdown
Dest    flow::scripts-to-build::90
Streams coffeescript-lint.lint, coffeescript-lint.report, coffeescript-lint.failOnError, coffeescript-compile

karma-get-vendor

Source  application/ngCore/vendor/angular-mocks/angular-mocks.js, application/ngCore/vendor/angular-jasmine-helpers/angular-jasmine-helpers.js, application/ngCore/src/app/**/*.spec.js, application/ngCore/src/app/**/*.spec.coffee
Dest    flow::karma-single-run::20
Streams none

karma-single-run

Source  application/ngCore/build/scripts/**/*.js
Dest    none
Streams karma-sort-vendor, karma.single-run, karma.reporter

less-to-build

Source  application/ngCore/src/app/**/*.less
Dest    flow::styles-to-build::90
Streams less-compile

code-to-strip

Source  application/ngCore/src/**/*
Dest    application/ngCore/build
Streams strip-code

assets-to-build

Source  application/ngCore/src/assets/**/*
Dest    application/ngCore/build/assets
Streams none

assets-to-compile

Source  application/ngCore/src/assets/**/*
Dest    application/ngCore/bin/assets
Streams none

html-to-build

Source  !application/ngCore/src/app/**/*.tpl.html, application/ngCore/src/index.html, application/ngCore/src/app/**/*.html
Dest    application/ngCore/build
Streams webapp-html-template.build

html-to-compile

Source  !application/ngCore/src/app/**/*.tpl.html, application/ngCore/src/index.html, application/ngCore/src/app/**/*.html
Dest    application/ngCore/bin
Streams webapp-html-template.compile

scripts-to-lint

Source  !application/ngCore/src/app/**/*.stub.js, !application/ngCore/src/app/**/*.spec.js, application/ngCore/src/app/**/*.js
Dest    none
Streams webapp-lintjs.lint, webapp-lintjs.reporter, webapp-lintjs.failOnError

test-scripts-to-lint

Source  application/ngCore/src/app/**/*.spec.js
Dest    none
Streams webapp-lintjs.lint, webapp-lintjs.reporter, webapp-lintjs.failOnError

scripts-to-build

Source  !application/ngCore/src/app/**/*.stub.js, !application/ngCore/src/app/**/*.spec.js, application/ngCore/src/app/**/*.js
Dest    application/ngCore/build/scripts
Streams webapp-sort, webapp-tpl.scripts

vendor-scripts-to-build

Source  application/ngCore/vendor/angular/angular.js, application/ngCore/vendor/angular-ui-router/release/angular-ui-router.js, application/ngCore/vendor/lodash/dist/lodash.js, application/ngCore/vendor/es5-shim/es5-shim.js, application/ngCore/packages/pouchdb/pouchdb-2.2.3.js, application/ngCore/vendor/angular-pouchdb/angular-pouchdb.js
Dest    flow::scripts-to-build::60
Streams webapp-scripts.vendor

styles-to-build

Source  application/ngCore/src/app/**/*.css
Dest    application/ngCore/build/styles
Streams webapp-lintcss.lint, webapp-lintcss.reporter, webapp-lintcss.failOnError, webapp-sort, webapp-tpl.styles

vendor-styles-to-build

Source  none
Dest    flow::styles-to-build::45
Streams webapp-styles.vendor

styles-to-compile

Source  application/ngCore/build/styles/**/*.css
Dest    application/ngCore/bin/assets
Streams webapp-sort, webapp-concatcss, webapp-minjs, webapp-tpl.compile-styles

Starting tasks: flow::code-to-strip
Queued tasks: clean::scripts-to-build, flow::templates-to-build, flow::coffee-to-build, flow::vendor-scripts-to-build, flow::scripts-to-build, flow::karma-get-vendor, flow::karma-single-run, flow::code-to-strip
Starting task: clean::scripts-to-build
[scripts-to-build] Cleaning application/ngCore/build/scripts
Starting task: flow::templates-to-build
[templates-to-build] Starting run.
[templates-to-build] Piping stream to angular.tplCache.
[templates-to-build] Merging with scripts-to-build@95
Starting task: flow::coffee-to-build
[coffee-to-build] Starting run.
[coffee-to-build] Piping stream to coffeescript-lint.lint.
[coffee-to-build] Piping stream to coffeescript-lint.report.
[coffee-to-build] Piping stream to coffeescript-lint.failOnError.
[coffee-to-build] Piping stream to coffeescript-compile.
[coffee-to-build] Merging with scripts-to-build@90
Starting task: flow::vendor-scripts-to-build
[vendor-scripts-to-build] Starting run.
[vendor-scripts-to-build] Piping stream to webapp-scripts.vendor.
[vendor-scripts-to-build] Merging with scripts-to-build@60
Starting task: flow::scripts-to-build
[scripts-to-build] Starting run.
[scripts-to-build] Added stream to queue: merge@60
[scripts-to-build] Added stream to queue: merge@90
[scripts-to-build] Added stream to queue: merge@95
[scripts-to-build] Piping stream to merge@60.
[scripts-to-build] Piping stream to merge@90.
[scripts-to-build] Piping stream to merge@95.
[scripts-to-build] Handing stream off to webapp-sort.
[scripts-to-build] Piping stream to webapp-tpl.scripts.
[scripts-to-build] Adding destination stream application/ngCore/build/scripts
Starting task: flow::karma-get-vendor
[karma-get-vendor] Starting run.
[karma-get-vendor] Merging with karma-single-run@20
Starting task: flow::karma-single-run
[karma-single-run] Starting run.
[karma-single-run] Added stream to queue: merge@20
[karma-single-run] Handing stream off to karma-sort-vendor.
[karma-single-run] Piping stream to merge@20.
[karma-single-run] Handing stream off to karma.single-run.
[karma-single-run] Piping stream to karma.reporter.
Starting Karma Server.
PhantomJS 1.9.7 (Mac OS X): Executed 129 of 129 SUCCESS (0.308 secs / 0.324 secs)
>
joshdmiller commented 10 years ago

Wow, that is a long block...

I think Karma might be killing the node process. With --verbose, there should be a run time when Warlock finishes all the tasks. So whatever happens when Karma runs, Warlock never continues after the task "completes". Let me see if I have a note somewhere on how I solved that with Grunt...

Merott commented 10 years ago

Any thoughts?

I've had time to dig in a little more in Warlock and the original Grunt-based build system, but haven't been able to do much other than to verify that Karma does cause the process to end.

joshdmiller commented 10 years ago

The problem with Grunt-based config was the port, which doesn't make any sense to me (ngbp/ngbp#20 and karma-runner/grunt-karma#30). This was the fix then: ngbp/ngbp@f66cfcc622600762d0489f5db6b60ae2b6cbc6c6.

Try changing the runnerPort option to 9101 and see if that fixes it.

Merott commented 10 years ago

Tried it now. Unfortunately it doesn't help.

runnerPort is only used when using .run, but we're not doing that, so I guess it makes no difference here.

This is an old thread, but does it help? https://github.com/karma-runner/gulp-karma/issues/3

joshdmiller commented 10 years ago

@Merott Maybe, but updating to the latest Karma doesn't help. However, I may have made some progress with a minor bug fix in Warlock (v0.0.1-alpha.3) and spawning Karma as a child process.

Update your Warlock to the latest (maybe just "warlock-engine": "latest" in your package.json) and give this spell-karma feature branch a try: https://github.com/ngbp/spell-karma/tree/feature-child-proc.

And stand on one leg on the next full moon.

Merott commented 10 years ago

Tried it, and unfortunately the whole process still ends as soon as Karma is done.

I guess I probably should wait till the next full moon.

Merott commented 10 years ago

This is where the process finally dies...

// .../warlock-spell-karma/node_modules/karma/lib/server.js (line 219)

globalEmitter.emitAsync('exit').then(function() {
  // don't wait forever on webServer.close() because
  // pending client connections prevent it from closing.
  var closeTimeout = setTimeout(removeAllListeners,
     webServerCloseTimeout);

  // shutdown the server...
  webServer.close(function() {
     clearTimeout(closeTimeout);
     removeAllListeners();
  });

  // shutdown socket.io flash transport, if defined
  if(socketServer.flashPolicyServer) {
     console.log('And...');
     socketServer.flashPolicyServer.close();
     console.log("I don't get the chance to run.");
  }
});

I don't really know what I'm looking at here, but thought it might be worth pointing it out!

joshdmiller commented 10 years ago

Can you fork the warlock branch of ngbp and add whatever plugin you need to make it fail so I can take a look? It's not doing it for me, but I can't see your code.

Merott commented 10 years ago

Here it is: https://github.com/Merott/ngbp/commit/9a5fa4539d313c5afa2e611e5f4a372ce1f0a66b

The plugin just throws an error, but won't run when it depends on flow::karma-single-run. I try to run it using warlock -f flow::code-to-strip