Skip to content
This repository was archived by the owner on Jul 13, 2020. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
105 changes: 46 additions & 59 deletions test/custom-loader.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,105 +8,92 @@ describe('Custom Loader', function () {
it('should support ES6 scripts', function (done) {
customLoader.import('test/loader/test')
.then(function (m) {
setTimeout(function () {
expect(m.loader).to.be.equal('custom');
done();
});
}, done)
expect(m.loader).to.be.equal('custom');
})
.then(done, done)
});

it('should support AMD scripts', function (done) {
customLoader.import('test/loader/amd')
.then(function (m) {
setTimeout(function () {
expect(m.format).to.be.equal('amd');
done();
});
}, done)
expect(m.format).to.be.equal('amd');
})
.then(done, done);
});
});

describe('special #locate path rule', function () {
describe('special #locate path rule', function a() {

it('should support special loading rules', function (done) {
customLoader.import('path/custom')
.then(function (m) {
setTimeout(function () {
expect(m.path).to.be.ok();
done();
});
}, done)
});
expect(m.path).to.be.ok();
})
.then(done, done);
})

});

describe('errors', function () {

function dummyLoad(file, cb) {
System.import(file)
.then(function () {
setTimeout(function () {
expect(false, 'should not be successful').to.be.ok();
cb();
});
})
.catch(function (e) {
setTimeout(function () {
cb(e);
});
})
;
function supposeToFail() {
expect(false, 'should not be successful').to.be.ok();
}

it('should make the normalize throw', function (done) {
dummyLoad('test/loader/error1-parent', function (e) {
expect(e).to.be.match(/Error loading "error1" at \S+error1\.js\nError loading "error1" from "test\/loader\/error1-parent"/);
done();
});
customLoader.import('test/loader/error1-parent')
.then(supposeToFail, function (e) {
expect(e).to.be.match(/Error loading "test\/loader\/error1-parent" at \S+error1-parent\.js/);
})
.then(done, done);
});

it('should make the locate throw', function (done) {
dummyLoad('test/loader/error2', function (e) {
expect(e).to.be.match(/Error loading "test\/loader\/error2" at \S+test\/loader\/error2\.js/);
done();
});
customLoader.import('test/loader/error2')
.then(supposeToFail, function (e) {
expect(e).to.be.match(/Error loading "test\/loader\/error2" at \S+test\/loader\/error2\.js/);
})
.then(done, done);
});

it('should make the fetch throw', function (done) {
dummyLoad('test/loader/error3', function (e) {
expect(e).to.be.match(/Error loading "test\/loader\/error3" at \S+test\/loader\/error3\.js/);
done();
});
customLoader.import('test/loader/error3')
.then(supposeToFail, function (e) {
expect(e).to.be.match(/Error loading "test\/loader\/error3" at \S+test\/loader\/error3\.js/);
})
.then(done, done);
});

it('should make the translate throw', function (done) {
dummyLoad('test/loader/error4', function (e) {
expect(e).to.be.match(/Error loading "test\/loader\/error4" at \S+test\/loader\/error4\.js/);
done();
});
customLoader.import('test/loader/error4')
.then(supposeToFail, function (e) {
expect(e).to.be.match(/Error loading "test\/loader\/error4" at \S+test\/loader\/error4\.js/);
})
.then(done, done);
});

it('should make the instantiate throw', function (done) {
dummyLoad('test/loader/error5', function (e) {
expect(e).to.be.match(/Error loading "test\/loader\/error5" at \S+test\/loader\/error5\.js/);
done();
});
customLoader.import('test/loader/error5')
.then(supposeToFail, function (e) {
expect(e).to.be.match(/Error loading "test\/loader\/error5" at \S+test\/loader\/error5\.js/);
})
.then(done, done);
});

});

});

describe('#normalize', function () {
it('should support async normalization', function (done) {
customLoader.normalize('asdfasdf').then(function (normalized) {
return customLoader.import(normalized)
}).then(function (m) {
setTimeout(function () {
customLoader.normalize('asdfasdf')
.then(function (normalized) {
return customLoader.import(normalized);
})
.then(function (m) {
expect(m.n).to.be.equal('n');
done();
});
})
.catch(done);
})
.then(done, done);
});
});
});
Loading