Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

feat(init): generate test-main.(js/coffee) for RequireJS projects #897

Closed
wants to merge 5 commits into
from

Conversation

Projects
None yet
2 participants
Member

cironunes commented Jan 22, 2014

I am working on issue #896. It still needs a lot of improvements and even tests. I really appreciate any suggestions.

@vojtajina vojtajina and 1 other commented on an outdated diff Feb 5, 2014

requirejs.config.tpl.js
@@ -0,0 +1,30 @@
+var tests = [];
+for (var file in window.__karma__.files) {
+ if (window.__karma__.files.hasOwnProperty(file)) {
@vojtajina

vojtajina Feb 5, 2014

Contributor

Normalize the paths to "module" ids (without the *.js suffix, etc.) - otherwise RequireJS treats the test files as "scripts" which causes many troubles...

Same for CoffeeScript version...

@cironunes

cironunes Feb 10, 2014

Member

I did not got it. Actually I just copied this from the docs. Could you explain?

@vojtajina

vojtajina Feb 14, 2014

Contributor

See

var pathToModule = function(path) {
return path.replace(/^\/base\//, '').replace(/\.js$/, '');
};

Yeah, we should update the docs too...

@vojtajina vojtajina commented on an outdated diff Feb 5, 2014

requirejs.config.tpl.js
@@ -0,0 +1,30 @@
+var tests = [];
+for (var file in window.__karma__.files) {
+ if (window.__karma__.files.hasOwnProperty(file)) {
+ if (/Spec\.js$/.test(file)) {
+ tests.push(file);
+ }
+ }
+}
+
+requirejs.config({
+ // Karma serves files from '/base'
+ baseUrl: '/base/src',
+
+ paths: {
@vojtajina

vojtajina Feb 5, 2014

Contributor

The path/shim section should be generated... I don't think we need that for the first version...

Contributor

vojtajina commented Feb 5, 2014

This looks great!

Currently karma init asks you "do you wanna use require?". If you say so, then it asks two questions about "where are your source/test files" (these files won't be included) and "where is your test-main.js?" (these will be included). I think instead of the second question, it should ask "do you wanna generate test-main.js/coffee?" If you say so, it generates test-main.js and not even ask the "include" question. If you say no, then it should ask the "include question".

What do you think?

Member

cironunes commented Feb 5, 2014

Thanks for the feedback @vojtajina!

I really liked it! I'm going to implement it today later and come back to discuss more.

Member

cironunes commented Feb 10, 2014

I just put the questions that way you said. Now I'm trying to figure out how to test it.

Member

cironunes commented Feb 20, 2014

@vojtajina, just updated here, can you take a look?

I updated the docs also. 😄

@vojtajina vojtajina commented on an outdated diff Mar 9, 2014

@@ -239,12 +249,23 @@ exports.init = function(config) {
sm.process(questions, function(answers) {
var cwd = process.cwd();
var configFile = config.configFile || 'karma.conf.js';
+ var requirejsConfigFile = path.resolve(
@vojtajina

vojtajina Mar 9, 2014

Contributor

I think we should generate the test-main.js file in the same folder as the karma.conf.js, rather than cwd.
What do you think?

@vojtajina vojtajina commented on an outdated diff Mar 9, 2014

formatter.writeConfigFile(configFilePath, processedAnswers);
+ if(_.contains(processedAnswers.frameworks, 'requirejs') && processedAnswers.generateTestMain) {
@vojtajina

vojtajina Mar 9, 2014

Contributor

There is no way to set generateTestMain without using RequireJS, right? I think you can simplify this condition to just if (proccessedAnswers.generateTestMain)

@vojtajina vojtajina commented on an outdated diff Mar 9, 2014

formatter.writeConfigFile(configFilePath, processedAnswers);
+ if(_.contains(processedAnswers.frameworks, 'requirejs') && processedAnswers.generateTestMain) {
+ formatter.writeRequirejsConfigFile(requirejsConfigFilePath);
@vojtajina

vojtajina Mar 9, 2014

Contributor

Also the test-main.js has to be added to files (as included: true), you can do this inside processAnswers(), add it into processedAnswers.files

@vojtajina vojtajina commented on an outdated diff Mar 9, 2014

formatter.writeConfigFile(configFilePath, processedAnswers);
+ if(_.contains(processedAnswers.frameworks, 'requirejs') && processedAnswers.generateTestMain) {
+ formatter.writeRequirejsConfigFile(requirejsConfigFilePath);
+ console.log(colorScheme.success(
+ 'test-main file for RequireJS generated at "' + requirejsConfigFile + '".\n'
@vojtajina

vojtajina Mar 9, 2014

Contributor

How about 'RequireJS bootsrap file generated at...`

@vojtajina vojtajina commented on an outdated diff Mar 9, 2014

@@ -126,6 +127,14 @@ var questions = [{
multiple: true,
validate: validatePattern
+}, {
+ id: 'generateTestMain',
+ question: 'Do you wanna generate the test-main.js/coffe file?',
+ hint: 'This will bootstrap your tests by configuring Require.js and ' +
@vojtajina

vojtajina Mar 9, 2014

Contributor

How about:
question: Do you wanna generate a bootstrap file for RequireJS?
hint: This will generate test-main.js/coffee that configures RequiseJS and starts the tests.

Contributor

vojtajina commented Mar 9, 2014

@cironunes this is really good! I sent some more comments.

Can you also update the RequireJS docs to mention karma init? Because now, with your update, the whole thing will be much simpler.

I'm about to push 0.12 release and I would like to include this in, so let me know if you have time to work on it in the next couple of days, otherwise I'm happy to finish it.

Thanks a lot for this!

@vojtajina vojtajina added this to the v0.12 milestone Mar 9, 2014

@vojtajina vojtajina self-assigned this Mar 9, 2014

Member

cironunes commented Mar 9, 2014

@vojtajina cool!

I appreciate your feedback and I'm going to work on it.

I just updated the docs and the question + hint about the config file.

FYI I'm planning to squash commits before merge

Member

cironunes commented Mar 10, 2014

Missing two things that I still didn't figure out:

  • Add the test-main.js for last
  • Unit tests
Contributor

vojtajina commented Mar 10, 2014

Awesome. Do you need any help?

Member

cironunes commented Mar 10, 2014

Yes, any help would be nice!

Actually if you want to finish it would be good too. But if you want to just guide me, I can do that.

Contributor

vojtajina commented Mar 10, 2014

Wait, you already did the "add test-main.js", right?
I think this is good! I will just squash it into a single commit and merging...

Member

cironunes commented Mar 10, 2014

I already did, but it should be added for last, right? And the tests are failing. Actually I'm not sure if I wrote reasonable tests for that...

Contributor

vojtajina commented Mar 10, 2014

All right, I did subtle changes, fixed the tests, made regexp more flexible... here is my changes vojtajina/karma@50df045

Contributor

vojtajina commented Mar 10, 2014

Ok, squashed and merged as 85900c9 and a99c387

Thanks a lot @cironunes !!!

@vojtajina vojtajina closed this Mar 10, 2014

@cironunes cironunes deleted the cironunes:requirejs/test-main branch Mar 10, 2014

Member

cironunes commented Mar 10, 2014

Pretty nice!

You're welcome and thank you for Karma! 😄

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment