jejacks0n / teaspoon

Teaspoon: Javascript test runner for Rails. Use Selenium, BrowserStack, or PhantomJS.
1.43k stars 243 forks source link

teaspoon + webpack = :sob: #507

Closed dreamalligator closed 7 years ago

dreamalligator commented 7 years ago

Hi all, I am having difficulty accessing modules in the AMD pattern that are bundled with webpack for my Teaspoon tests.

Example of such a pattern: define(['a', 'b'], function (a, b) {});. These anonymous defines are problematic.

I read the wiki on using RequireJS-with-Teaspoon, but although informative, not quite the steps for such a stack.

Currently my workaround is extracting the methods I want to test and muddying the global namespace. Such as window.myMethodToTest.. but this makes me 😿.

Any suggestions or help are greatly appreciated.

#= require my_module will give ReferenceError: Can't find variable: define

and I suppose it is possible to create a faux test bundle with webpack and require it via Teaspoon's spec_helper? or possibly do something with adding test fixtures and altering https://github.com/jejacks0n/teaspoon/blob/master/app/views/teaspoon/suite/_boot.html.erb

jejacks0n commented 7 years ago

Do you have whatever defines define required in your spec helper?

dreamalligator commented 7 years ago

I wound up making a faux test application Webpack config entry.

entry: {
  '/spec/javascripts/faux_application': './spec/javascripts/tests/test_manifest.js.coffee'
}

and updated the teaspoon_env suite.matcher to be that output file. i.e. "spec/javascripts/faux_application.js" in this example.

and other specific things to my project. Marking as closed, thanks!