-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5 from jstrimpel/master
make local file extension optional
- Loading branch information
Showing
2 changed files
with
55 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
const MomentLocalesPlugin = require('./index.js'); | ||
|
||
test('returns a ContextReplacementPlugin instance when locales are passed', () => { | ||
const result = new MomentLocalesPlugin({ | ||
localesToKeep: ['en-gb', 'ru'], | ||
}); | ||
|
||
expect(result.constructor.name).toEqual('ContextReplacementPlugin'); | ||
expect(result.newContentRegExp.toString()).toEqual( | ||
'/(en-gb(\\.js)?|ru(\\.js)?)$/' | ||
); | ||
}); | ||
|
||
test('returns an IgnorePlugin instance when locales are not passed', () => { | ||
const result = new MomentLocalesPlugin({ | ||
localesToKeep: [], | ||
}); | ||
|
||
expect(result.constructor.name).toEqual('IgnorePlugin'); | ||
}); | ||
|
||
test('works when no options are passed', () => { | ||
const result = new MomentLocalesPlugin(); | ||
|
||
expect(result.constructor.name).toEqual('IgnorePlugin'); | ||
}); | ||
|
||
test('normalizes locales to match file names', () => { | ||
const result = new MomentLocalesPlugin({ | ||
localesToKeep: ['en-gb-foo'], | ||
}); | ||
|
||
expect(result.newContentRegExp.toString()).toMatch(/en-gb(\\.js)?/); | ||
}); | ||
|
||
describe('validation', () => { | ||
test('throws when an unknown option is passed', () => { | ||
expect(() => new MomentLocalesPlugin({ foo: 'bar' })).toThrow( | ||
/unknown option/ | ||
); | ||
}); | ||
|
||
test('throws when not an array is passed into `localesToKeep`', () => { | ||
expect(() => new MomentLocalesPlugin({ localesToKeep: {} })).toThrow( | ||
/Expected .+ option to be an array, received/ | ||
); | ||
}); | ||
|
||
test('throws when an invalid locale is passed into `localesToKeep`', () => { | ||
expect( | ||
() => new MomentLocalesPlugin({ localesToKeep: ['foo-bar'] }) | ||
).toThrow(/Moment.js doesn’t include/); | ||
}); | ||
}); |