Skip to content

Commit

Permalink
Fix errors in relative filesystem loader
Browse files Browse the repository at this point in the history
  • Loading branch information
hason committed May 20, 2020
1 parent 128a9e8 commit 4f282f3
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 5 deletions.
8 changes: 7 additions & 1 deletion src/lib/loader/relative-filesystem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,13 @@ export class TwingLoaderRelativeFilesystem implements TwingLoaderInterface {
throw new TwingErrorLoader(this.errorCache.get(name), -1, from);
};

return Promise.resolve(_do());
return new Promise((resolve, reject) => {
try {
resolve(_do());
} catch (e) {
reject(e)
}
});
}

protected normalizeName(name: string) {
Expand Down
4 changes: 2 additions & 2 deletions test/tests/unit/lib/cache/filesystem/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ tape('cache filesystem', (test: Test) => {
});

try {
await cache.write('foo', null);
await cache.write('foo', 'bar');

test.fail();
}
Expand All @@ -49,7 +49,7 @@ tape('cache filesystem', (test: Test) => {
});

try {
await cache.write('foo', null);
await cache.write('foo', 'bar');

test.fail();
}
Expand Down
6 changes: 4 additions & 2 deletions test/tests/unit/lib/helpers/format-date-time/test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import * as tape from 'tape';
import {formatDateTime} from "../../../../../../src/lib/helpers/format-date-time";

const {DateTime} = require('luxon');
const {DateTime, Settings} = require('luxon');

Settings.defaultLocale = 'en';

// Thursday, January 1, 1970 4:12:29 PM
let date = DateTime.fromMillis(58349457, {zone: 'UTC'});
Expand Down Expand Up @@ -210,4 +212,4 @@ tape('format-date-time', (test) => {
test.same(formatDateTime(date4, 'U'), '102744749', 'Seconds since the Unix Epoch (January 1 1970 00:00:00 GMT)');

test.end();
});
});
12 changes: 12 additions & 0 deletions test/tests/unit/lib/loader/chain/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {resolve, join} from "path";
import {TwingLoaderChain} from "../../../../../../src/lib/loader/chain";
import {TwingLoaderArray} from "../../../../../../src/lib/loader/array";
import {TwingLoaderFilesystem} from "../../../../../../src/lib/loader/filesystem";
import {TwingLoaderRelativeFilesystem} from "../../../../../../src/lib/loader/relative-filesystem";
import {TwingErrorLoader} from "../../../../../../src/lib/error/loader";
import {TwingError} from "../../../../../../src/lib/error";

Expand Down Expand Up @@ -354,6 +355,17 @@ tape('loader chain', (test) => {
test.end();
});

test.test('when a relative filesystem loader throws an error in findTemplate', async (test) => {
let loader = new TwingLoaderChain([
new TwingLoaderRelativeFilesystem(),
new TwingLoaderArray({'foo': 'bar'}),
]);

test.equals(await loader.resolve('foo', null), 'foo');

test.end();
});

test.test('when all loaders throw loader-related errors', async (test) => {
let loader1 = new TwingLoaderArray({});
sinon.stub(loader1, 'resolve').returns(Promise.reject(new TwingErrorLoader('foo', 1, null)));
Expand Down

0 comments on commit 4f282f3

Please sign in to comment.