-
Notifications
You must be signed in to change notification settings - Fork 10
Added AMD support to karma-ng-json2js-preprocessor #8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
8015a79
6202ad6
6b9f168
dba1523
3bac37e
b2cb034
06b96fc
47de4f5
38d3f2e
8778a36
dc9a7d0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,3 +3,4 @@ | |
|
|
||
| /node_modules | ||
| /libpeerconnection.log | ||
| .idea | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,70 @@ | ||
| 'use strict'; | ||
|
|
||
| module.exports = function (config) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There's a lot of duplication in this file as well. How about creating |
||
| var preprocessors = config.preprocessors; | ||
| // put JSON data into a mock | ||
| preprocessors['**/*.json'] = 'ng-json2js'; | ||
|
|
||
| config.set({ | ||
| frameworks: ['jasmine', 'requirejs'], | ||
|
|
||
| // base path, that will be used to resolve files and exclude | ||
| basePath: '', | ||
|
|
||
| // list of files / patterns to load in the browser | ||
| files: [ | ||
| 'test/main-test.js', | ||
| {pattern: 'test/vendor/angular.js', included: false}, | ||
| {pattern: 'test/vendor/angular-mocks.js', included: false}, | ||
| {pattern: 'test/fixtures/*.json', included: false}, | ||
| {pattern: 'test/ng-json2js.requirejs.spec.js', included: false}, | ||
| {pattern: 'karma.requirejs.conf.js', included: false, served: false}, | ||
| ], | ||
|
|
||
| // list of files to exclude | ||
| exclude: [], | ||
|
|
||
| preprocessors: preprocessors, | ||
|
|
||
| plugins: config.plugins.concat([ | ||
| require('./lib/index.js'), | ||
| ]), | ||
|
|
||
| // test results reporter to use | ||
| // possible values: dots || progress || growl | ||
| reporters: ['progress'], | ||
|
|
||
| // web server port | ||
| port: 9876, | ||
|
|
||
| // cli runner port | ||
| runnerPort: 9100, | ||
|
|
||
| // enable / disable colors in the output (reporters and logs) | ||
| colors: true, | ||
|
|
||
| // level of logging | ||
| // possible values: LOG_DISABLE || LOG_ERROR || LOG_WARN || LOG_INFO || LOG_DEBUG | ||
| logLevel: config.LOG_INFO, | ||
|
|
||
| // enable / disable watching file and executing tests whenever any file changes | ||
| autoWatch: true, | ||
|
|
||
| // Start these browsers, currently available: | ||
| // - Chrome | ||
| // - ChromeCanary | ||
| // - Firefox | ||
| // - Opera | ||
| // - Safari (only Mac) | ||
| // - PhantomJS | ||
| // - IE (only Windows) | ||
| browsers: ['PhantomJS'], | ||
|
|
||
| // If browser does not capture in given timeout [ms], kill it | ||
| captureTimeout: 5000, | ||
|
|
||
| // Continuous Integration mode | ||
| // if true, it capture browsers, run tests and exit | ||
| singleRun: false, | ||
| }); | ||
| }; | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,7 +2,18 @@ module.exports = (function () { | |
| 'use strict'; | ||
|
|
||
| var util = require('util'), | ||
| TEMPLATE = 'angular.module(\'%s\', []).constant(\'%s\', %s);\n'; | ||
| TEMPLATE = | ||
| '\'use strict\';\n' + | ||
| 'function %sFunction (angular) {\n' + | ||
| ' angular.module(\'%s\', []).constant(\'%s\', %s);\n' + | ||
| '}\n' + | ||
| 'if (typeof define === \'function\' && define.amd) {\n' + | ||
| ' require([\'angular\'], function (angular) {\n' + | ||
| ' %sFunction(angular);\n' + | ||
| ' });\n' + | ||
| '} else {\n' + | ||
| ' %sFunction(angular);\n' + | ||
| '}\n'; | ||
|
|
||
| function createNgJson2jsPreprocessor(logger, basePath, config) { | ||
| config = config || {}; | ||
|
|
@@ -26,7 +37,7 @@ module.exports = (function () { | |
| }); | ||
| file.path = file.path + '.js'; | ||
|
|
||
| done(util.format(TEMPLATE, jsonPath, componentName, content)); | ||
| done(util.format(TEMPLATE, componentName, jsonPath, componentName, content, componentName, componentName)); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is getting unreadable with this many parameters... How about turning template({
jsonPath: jsonPath,
componentName: componentName,
content: content,
}); |
||
| }; | ||
| } | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,6 @@ | ||
| { | ||
| "name": "karma-ng-json2js-preprocessor", | ||
| "version": "1.0.1-pre", | ||
| "version": "1.0.1", | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please don't modify this. |
||
| "description": "A Karma plugin. Compile JSON files to Angular constants on the fly.", | ||
| "main": "./lib/index.js", | ||
| "repository": { | ||
|
|
@@ -12,6 +12,7 @@ | |
| "karma-preprocessor", | ||
| "angularjs", | ||
| "angular", | ||
| "requirejs", | ||
| "json2js" | ||
| ], | ||
| "author": { | ||
|
|
@@ -35,6 +36,7 @@ | |
| "karma": "0.12.24", | ||
| "karma-jasmine": "0.1.5", | ||
| "karma-phantomjs-launcher": "0.1.4", | ||
| "karma-requirejs": "^0.2.2", | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Remove the caret; I prefer to have devDependencies declared strictly. |
||
| "load-grunt-tasks": "0.6.0", | ||
| "time-grunt": "1.0.0" | ||
| }, | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| /* global window */ | ||
|
|
||
| var file, testFiles = []; | ||
|
|
||
| for (file in window.__karma__.files) { | ||
| if (/spec.*\.js$/.test(file)) { | ||
| testFiles.push(file); | ||
| } | ||
| if (/.*\.json\.js$/.test(file)) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It seems this all could be handled with one regex, sth like: |
||
| testFiles.push(file); | ||
| } | ||
| } | ||
|
|
||
| require({ | ||
| baseUrl: 'http://localhost:9876/base/', | ||
| paths:{ | ||
| angular: 'test/vendor/angular', | ||
| angularmocks: 'test/vendor/angular-mocks', | ||
| }, | ||
| shim: { | ||
| angular: { | ||
| exports: 'angular', | ||
| }, | ||
| angularmocks: { | ||
| deps: ['angular'], | ||
| }, | ||
| }, | ||
| deps: testFiles, | ||
|
|
||
| callback: window.__karma__.start, | ||
| }); | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,56 @@ | ||
| /* global define */ | ||
|
|
||
| 'use strict'; | ||
|
|
||
| define(['angular', 'angularmocks'], function (angular) { | ||
| describe('json2j preprocessor', function () { | ||
|
|
||
| beforeEach(module('test/fixtures/empty.json')); | ||
| beforeEach(module('test/fixtures/complex.json')); | ||
|
|
||
| it('should work on an empty object', function () { | ||
| var testFixturesEmpty; | ||
| inject(function (_testFixturesEmpty_) { | ||
| testFixturesEmpty = _testFixturesEmpty_; | ||
| }); | ||
|
|
||
| expect(testFixturesEmpty).toEqual({}); | ||
| }); | ||
|
|
||
| var checkComplexObject = function (testFixturesComplex) { | ||
| expect(testFixturesComplex).toEqual({ | ||
| field: 'property', | ||
| subObject: [ | ||
| 'arrayElem1', | ||
| 'arrayElem2', | ||
| ], | ||
| anotherSubObject: { | ||
| subSubObject: { | ||
| field: 'property', | ||
| }, | ||
| }, | ||
| }); | ||
| }; | ||
|
|
||
| it('should work on a complex object', function () { | ||
| var testFixturesComplex; | ||
| inject(function (_testFixturesComplex_) { | ||
| testFixturesComplex = _testFixturesComplex_; | ||
| }); | ||
|
|
||
| checkComplexObject(testFixturesComplex); | ||
| }); | ||
|
|
||
| it('should allow accessing the json during configuration phase', function () { | ||
| var injectedDuringConfig; | ||
| angular.module('testModule', ['test/fixtures/complex.json']).config(function (_testFixturesComplex_) { | ||
| injectedDuringConfig = _testFixturesComplex_; | ||
| }); | ||
|
|
||
| inject(module('testModule')); | ||
|
|
||
| checkComplexObject(injectedDuringConfig); | ||
| }); | ||
| }); | ||
|
|
||
| }); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Was the previous port causing issues?