Files
workbox/packages/sw-cli/test/node/utils-generate-glob-pattern.js
T
Matt GauntandAddy Osmani 1f62f7a2b3 Test sweep (#420)
* Big ole test re-jig

* Current work

* Moving all tests over to the test runner

* Fixing last nits in the build and test runner

* Adding precaching integration tests

* Moving sw-appcache-behavior to integration test

* Adding bg-sync to test suite again - incoming fails

* Fixing the last pieces of the test sweep

* Removing logs

* Removing number of repeats in tests - should be determined by the individual tests - not the runner

* Small move around with sw-appcache

* Retry the end to end-to-end test
2017-04-07 10:59:53 -07:00

58 lines
1.7 KiB
JavaScript

const generateGlobPattern = require('../../src/lib/utils/generate-glob-pattern');
const errors = require('../../src/lib/errors');
require('chai').should();
describe('src/lib/utils/generate-glob-pattern.js', function() {
it('should handle a single file extension', function() {
const globPattern = generateGlobPattern(['txt']);
globPattern.should.equal('**/*.txt');
});
it('should handle a multiple file extensions', function() {
const globPattern = generateGlobPattern(['txt', 'js']);
globPattern.should.equal('**/*.{txt,js}');
});
it('should be able to handle a bad fileExtentionsToCache iput', function() {
const badInput = [
undefined,
null,
'',
{},
[],
[null],
[true],
[false],
[{}],
true,
false,
];
return badInput.reduce((promiseChain, input) => {
return promiseChain.then(() => {
try {
generateGlobPattern(input);
throw new Error('Expected to throw error.');
} catch(err) {
if (err.message !== errors['no-file-extensions-to-cache']) {
throw new Error('Unexpected error: ' + err.message);
}
}
});
}, Promise.resolve());
});
// fileExtensionsToCache - Add warning if the extension name has a '.' as
// first character
it('should be able to handle a bad file extension', function() {
try {
generateGlobPattern(['.example']);
throw new Error('Expected to throw error.');
} catch(err) {
if (err.message !== errors['no-file-extensions-to-cache']) {
throw new Error('Unexpected error: ' + err.message);
}
}
});
});