Skip to content

Commit

Permalink
Merge pull request #4 from ianmcgregor/develop
Browse files Browse the repository at this point in the history
🐛 Fix group api issue and update tests - fixes #3
  • Loading branch information
ianmcgregor authored Jun 12, 2017
2 parents 38bb0be + 60c01bc commit 1d03b15
Show file tree
Hide file tree
Showing 10 changed files with 106 additions and 41 deletions.
14 changes: 10 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
sudo: false
dist: trusty
language: node_js
node_js:
- 0.10
- 6
addons:
firefox: "30.0"
apt:
packages:
- google-chrome-stable
before_install:
- 'npm install -g karma-cli'
before_script:
- export CHROME_BIN=chromium-browser
- export DISPLAY=:99.0
- sh -e /etc/init.d/xvfb start
- sleep 3
before_script:
- npm i -g karma karma-cli
13 changes: 4 additions & 9 deletions dist/assets-loader.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions dist/assets-loader.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/assets-loader.min.js

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions examples/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ <h2>video</h2>
var loader = assetsLoader({ log: true })
.add({
id: 'video',
url: 'https://dl.dropboxusercontent.com/u/15470024/prototypes/video/counter.webm',
url: 'https://ianmcgregor.co/prototypes/video/counter.webm',
blob: true
})
.on('error', function(error) {
Expand Down Expand Up @@ -109,7 +109,7 @@ <h2>group b</h2>
})
.add({
id: 'groupB',
basePath: 'https://dl.dropboxusercontent.com/u/15470024/prototypes/audio/',
basePath: 'https://ianmcgregor.co/prototypes/audio/',
assets: sounds
})
.on('error', function(error) {
Expand Down Expand Up @@ -200,7 +200,7 @@ <h2>group b</h2>
var loader = assetsLoader({ log: true })
.add({
id: 'video',
url: 'https://dl.dropboxusercontent.com/u/15470024/prototypes/video/counter.webm',
url: 'https://ianmcgregor.co/prototypes/video/counter.webm',
blob: true
})
.on('error', function(error) {
Expand Down Expand Up @@ -257,7 +257,7 @@ <h2>group b</h2>
})
.add({
id: 'groupB',
basePath: 'https://dl.dropboxusercontent.com/u/15470024/prototypes/audio/',
basePath: 'https://ianmcgregor.co/prototypes/audio/',
assets: [{
id: 'select',
url: 'select.ogg'
Expand Down
6 changes: 6 additions & 0 deletions karma.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@ module.exports = function(config) {
// base path, that will be used to resolve files and exclude
basePath: '',

client: {
mocha: {
timeout: 20000
}
},

plugins: [
'karma-mocha',
'karma-chai',
Expand Down
6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "assets-loader",
"version": "0.5.0",
"version": "0.5.1",
"description": "A simple batch assets loader.",
"keywords": [
"loader",
Expand All @@ -16,7 +16,9 @@
"license": "MIT",
"main": "src/index.js",
"scripts": {
"test": "./node_modules/.bin/karma start --single-run --browsers Firefox"
"start": "gulp",
"build": "gulp release",
"test": "karma start --single-run --browsers Chrome"
},
"readmeFilename": "README.md",
"repository": {
Expand Down
13 changes: 4 additions & 9 deletions src/group.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,22 +37,17 @@ module.exports = function createGroup(config) {
if (!arguments.length) {
return assets;
}
return map[id];
if (map[id]) {
return map[id];
}
return loaders[id];
};

var find = function(id) {
if (get(id)) {
return get(id);
}
var found = null;
// assets.filter(function(asset) {
// return asset.type === 'group';
// }).map(function(asset) {
// return loaders[asset.id];
// }).some(function(loader) {
// found = loader.find(id);
// return !!found;
// });
Object.keys(loaders).some(function(key) {
found = loaders[key].find && loaders[key].find(id);
return !!found;
Expand Down
20 changes: 10 additions & 10 deletions test/assets.json
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
{
"image": [
"http://placekitten.com/g/200/300",
"http://placekitten.com/1000/1000",
"http://placekitten.com/g/400/200",
"http://placekitten.com/g/200/150"
"https://ianmcgregor.co/prototypes/images/cat_01.jpg",
"https://ianmcgregor.co/prototypes/images/cat_02.jpg",
"https://ianmcgregor.co/prototypes/images/cat_03.jpg",
"https://ianmcgregor.co/prototypes/images/cat_04.jpg"
],
"audio": [
{
"ogg": "https://dl.dropboxusercontent.com/u/15470024/prototypes/audio/music.ogg",
"mp3": "https://dl.dropboxusercontent.com/u/15470024/prototypes/audio/music.mp3"
"ogg": "https://ianmcgregor.co/prototypes/audio/music.ogg",
"mp3": "https://ianmcgregor.co/prototypes/audio/music.mp3"
}
],
"video": [
{
"mp4": "https://dl.dropboxusercontent.com/u/15470024/prototypes/video/counter.mp4",
"webm": "https://dl.dropboxusercontent.com/u/15470024/prototypes/video/counter.webm"
"mp4": "https://ianmcgregor.co/prototypes/video/counter.mp4",
"webm": "https://ianmcgregor.co/prototypes/video/counter.webm"
}
],
"json": [
"https://dl.dropboxusercontent.com/u/15470024/prototypes/test/test.json"
"https://ianmcgregor.co/prototypes/test/test.json"
],
"text": [
"https://dl.dropboxusercontent.com/u/15470024/prototypes/video/tracking/tracking_01.txt"
"https://ianmcgregor.co/prototypes/video/tracking/tracking_01.txt"
]
}
61 changes: 61 additions & 0 deletions test/group.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
const assetsLoader = require('../src/index.js');
const files = require('./files.js');

describe('asset loader', () => {

describe('group', () => {

let complete = false;
let loadProgress = 0;
let groupA = null;
let groupB = null;

const loader = assetsLoader()
.add({
id: 'groupA',
assets: files.images
})
.add({
id: 'groupB',
assets: [files.json]
});

beforeEach(function(done) {
if (complete) {
done();
return;
}
loader
.on('progress', function(progress) {
loadProgress = progress;
})
.on('complete', () => {
complete = true;
groupA = loader.get('groupA');
groupB = loader.get('groupB');
done();
})
.on('error', function(error) {
console.log(error);
})
.start();
});

it('should have finished loading', () => {
expect(complete).equals(true);
expect(loadProgress).to.eql(1);
});

it('should have groupA', () => {
expect(groupA).to.exist;
expect(groupA.get()).to.have.lengthOf(2);
expect(groupA.get()[0]).to.have.property('type', 'jpg');
});

it('should have groupB', () => {
expect(groupB).to.exist;
expect(groupB.get()).to.have.lengthOf(1);
expect(groupB.get()[0]).to.have.property('type', 'json');
});
});
});

0 comments on commit 1d03b15

Please sign in to comment.