Skip to content

Commit 60c01bc

Browse files
committed
🐛 Fix group api issue and update tests
1 parent 33a4165 commit 60c01bc

10 files changed

+106
-41
lines changed

.travis.yml

+10-4
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,16 @@
1+
sudo: false
2+
dist: trusty
13
language: node_js
24
node_js:
3-
- 0.10
5+
- 6
46
addons:
5-
firefox: "30.0"
7+
apt:
8+
packages:
9+
- google-chrome-stable
610
before_install:
7-
- 'npm install -g karma-cli'
8-
before_script:
11+
- export CHROME_BIN=chromium-browser
912
- export DISPLAY=:99.0
1013
- sh -e /etc/init.d/xvfb start
14+
- sleep 3
15+
before_script:
16+
- npm i -g karma karma-cli

dist/assets-loader.js

+4-9
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/assets-loader.js.map

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/assets-loader.min.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/index.html

+4-4
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ <h2>video</h2>
5656
var loader = assetsLoader({ log: true })
5757
.add({
5858
id: 'video',
59-
url: 'https://dl.dropboxusercontent.com/u/15470024/prototypes/video/counter.webm',
59+
url: 'https://ianmcgregor.co/prototypes/video/counter.webm',
6060
blob: true
6161
})
6262
.on('error', function(error) {
@@ -109,7 +109,7 @@ <h2>group b</h2>
109109
})
110110
.add({
111111
id: 'groupB',
112-
basePath: 'https://dl.dropboxusercontent.com/u/15470024/prototypes/audio/',
112+
basePath: 'https://ianmcgregor.co/prototypes/audio/',
113113
assets: sounds
114114
})
115115
.on('error', function(error) {
@@ -200,7 +200,7 @@ <h2>group b</h2>
200200
var loader = assetsLoader({ log: true })
201201
.add({
202202
id: 'video',
203-
url: 'https://dl.dropboxusercontent.com/u/15470024/prototypes/video/counter.webm',
203+
url: 'https://ianmcgregor.co/prototypes/video/counter.webm',
204204
blob: true
205205
})
206206
.on('error', function(error) {
@@ -257,7 +257,7 @@ <h2>group b</h2>
257257
})
258258
.add({
259259
id: 'groupB',
260-
basePath: 'https://dl.dropboxusercontent.com/u/15470024/prototypes/audio/',
260+
basePath: 'https://ianmcgregor.co/prototypes/audio/',
261261
assets: [{
262262
id: 'select',
263263
url: 'select.ogg'

karma.conf.js

+6
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,12 @@ module.exports = function(config) {
66
// base path, that will be used to resolve files and exclude
77
basePath: '',
88

9+
client: {
10+
mocha: {
11+
timeout: 20000
12+
}
13+
},
14+
915
plugins: [
1016
'karma-mocha',
1117
'karma-chai',

package.json

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "assets-loader",
3-
"version": "0.5.0",
3+
"version": "0.5.1",
44
"description": "A simple batch assets loader.",
55
"keywords": [
66
"loader",
@@ -16,7 +16,9 @@
1616
"license": "MIT",
1717
"main": "src/index.js",
1818
"scripts": {
19-
"test": "./node_modules/.bin/karma start --single-run --browsers Firefox"
19+
"start": "gulp",
20+
"build": "gulp release",
21+
"test": "karma start --single-run --browsers Chrome"
2022
},
2123
"readmeFilename": "README.md",
2224
"repository": {

src/group.js

+4-9
Original file line numberDiff line numberDiff line change
@@ -37,22 +37,17 @@ module.exports = function createGroup(config) {
3737
if (!arguments.length) {
3838
return assets;
3939
}
40-
return map[id];
40+
if (map[id]) {
41+
return map[id];
42+
}
43+
return loaders[id];
4144
};
4245

4346
var find = function(id) {
4447
if (get(id)) {
4548
return get(id);
4649
}
4750
var found = null;
48-
// assets.filter(function(asset) {
49-
// return asset.type === 'group';
50-
// }).map(function(asset) {
51-
// return loaders[asset.id];
52-
// }).some(function(loader) {
53-
// found = loader.find(id);
54-
// return !!found;
55-
// });
5651
Object.keys(loaders).some(function(key) {
5752
found = loaders[key].find && loaders[key].find(id);
5853
return !!found;

test/assets.json

+10-10
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,26 @@
11
{
22
"image": [
3-
"http://placekitten.com/g/200/300",
4-
"http://placekitten.com/1000/1000",
5-
"http://placekitten.com/g/400/200",
6-
"http://placekitten.com/g/200/150"
3+
"https://ianmcgregor.co/prototypes/images/cat_01.jpg",
4+
"https://ianmcgregor.co/prototypes/images/cat_02.jpg",
5+
"https://ianmcgregor.co/prototypes/images/cat_03.jpg",
6+
"https://ianmcgregor.co/prototypes/images/cat_04.jpg"
77
],
88
"audio": [
99
{
10-
"ogg": "https://dl.dropboxusercontent.com/u/15470024/prototypes/audio/music.ogg",
11-
"mp3": "https://dl.dropboxusercontent.com/u/15470024/prototypes/audio/music.mp3"
10+
"ogg": "https://ianmcgregor.co/prototypes/audio/music.ogg",
11+
"mp3": "https://ianmcgregor.co/prototypes/audio/music.mp3"
1212
}
1313
],
1414
"video": [
1515
{
16-
"mp4": "https://dl.dropboxusercontent.com/u/15470024/prototypes/video/counter.mp4",
17-
"webm": "https://dl.dropboxusercontent.com/u/15470024/prototypes/video/counter.webm"
16+
"mp4": "https://ianmcgregor.co/prototypes/video/counter.mp4",
17+
"webm": "https://ianmcgregor.co/prototypes/video/counter.webm"
1818
}
1919
],
2020
"json": [
21-
"https://dl.dropboxusercontent.com/u/15470024/prototypes/test/test.json"
21+
"https://ianmcgregor.co/prototypes/test/test.json"
2222
],
2323
"text": [
24-
"https://dl.dropboxusercontent.com/u/15470024/prototypes/video/tracking/tracking_01.txt"
24+
"https://ianmcgregor.co/prototypes/video/tracking/tracking_01.txt"
2525
]
2626
}

test/group.spec.js

+61
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
const assetsLoader = require('../src/index.js');
2+
const files = require('./files.js');
3+
4+
describe('asset loader', () => {
5+
6+
describe('group', () => {
7+
8+
let complete = false;
9+
let loadProgress = 0;
10+
let groupA = null;
11+
let groupB = null;
12+
13+
const loader = assetsLoader()
14+
.add({
15+
id: 'groupA',
16+
assets: files.images
17+
})
18+
.add({
19+
id: 'groupB',
20+
assets: [files.json]
21+
});
22+
23+
beforeEach(function(done) {
24+
if (complete) {
25+
done();
26+
return;
27+
}
28+
loader
29+
.on('progress', function(progress) {
30+
loadProgress = progress;
31+
})
32+
.on('complete', () => {
33+
complete = true;
34+
groupA = loader.get('groupA');
35+
groupB = loader.get('groupB');
36+
done();
37+
})
38+
.on('error', function(error) {
39+
console.log(error);
40+
})
41+
.start();
42+
});
43+
44+
it('should have finished loading', () => {
45+
expect(complete).equals(true);
46+
expect(loadProgress).to.eql(1);
47+
});
48+
49+
it('should have groupA', () => {
50+
expect(groupA).to.exist;
51+
expect(groupA.get()).to.have.lengthOf(2);
52+
expect(groupA.get()[0]).to.have.property('type', 'jpg');
53+
});
54+
55+
it('should have groupB', () => {
56+
expect(groupB).to.exist;
57+
expect(groupB.get()).to.have.lengthOf(1);
58+
expect(groupB.get()[0]).to.have.property('type', 'json');
59+
});
60+
});
61+
});

0 commit comments

Comments
 (0)