Skip to content
Browse files

Add more tests for helpers#sortByConfig().

  • Loading branch information...
1 parent c33d4a5 commit f388de6dd87ecad1c9860f436a6c85ac9761d7b8 @paulmillr paulmillr committed May 5, 2012
Showing with 37 additions and 3 deletions.
  1. +8 −3 src/helpers.coffee
  2. +29 −0 test/helpers.coffee
View
11 src/helpers.coffee
@@ -58,8 +58,9 @@ sortAlphabetically = (a, b) ->
# If item path starts with 'vendor', it has bigger priority.
# TODO: check for config.vendorPath
sortByVendor = (config, a, b) ->
- aIsVendor = exports.startsWith a, config.vendorPaths
- bIsVendor = exports.startsWith b, config.vendorPaths
+ vendor = config.vendorPaths.slice().sort(sortAlphabetically)
+ aIsVendor = vendor.some((path) -> exports.startsWith a, path)
+ bIsVendor = vendor.some((path) -> exports.startsWith b, path)
if aIsVendor and not bIsVendor
-1
else if not aIsVendor and bIsVendor
@@ -111,7 +112,11 @@ sortByBefore = (config, a, b) ->
# Returns new sorted array.
exports.sortByConfig = (files, config) ->
if toString.call(config) is '[object Object]'
- files.slice().sort (a, b) -> sortByBefore config, a, b
+ cfg =
+ before: config.before ? []
+ after: config.after ? []
+ vendorPaths: config.vendorPaths ? []
+ files.slice().sort (a, b) -> sortByBefore cfg, a, b
else
files
View
29 test/helpers.coffee
@@ -8,6 +8,35 @@ describe 'helpers', ->
expect(helpers.replaceSlashes unix.config).to.eql win.config
describe '#sortByConfig()', ->
+ it 'should files by config.before', ->
+ files = ['backbone.js', 'jquery.js', 'underscore.js']
+ config =
+ before: ['jquery.js', 'underscore.js', 'backbone.js']
+ expect(helpers.sortByConfig files, config).to.eql config.before
+
+ it 'should files by config.after', ->
+ files = ['helper-1.js', 'backbone.js', 'helper-2.js']
+ config =
+ after: ['helper-1.js', 'helper-2.js']
+ expect(helpers.sortByConfig files, config).to.eql [
+ 'backbone.js', 'helper-1.js', 'helper-2.js'
+ ]
+
+ it 'should files by config.vendor', ->
+ files = ['vendor/backbone.js', 'jquery.js', 'meh/underscore.js']
+ config =
+ vendorPaths: ['vendor', 'meh']
+ expect(helpers.sortByConfig files, config).to.eql [
+ 'meh/underscore.js', 'vendor/backbone.js', 'jquery.js'
+ ]
+
+ it 'should files alphabetically', ->
+ files = ['z', 'e', 'a', 'd', 'c', 's', 'z']
+ config = {}
+ expect(helpers.sortByConfig files, config).to.eql [
+ 'a', 'c', 'd', 'e', 's', 'z', 'z'
+ ]
+
it 'should sort files by config correctly', ->
files = [
'a',

0 comments on commit f388de6

Please sign in to comment.
Something went wrong with that request. Please try again.