@travetto/asset
Advanced tools
Comparing version 0.0.4 to 0.0.5
{ | ||
"author": { | ||
"email": "timothy.soehnlin@gmail.com", | ||
"email": "timothy.soehnlin@gmail.com", | ||
"name": "Timothy Soehnlin" | ||
}, | ||
}, | ||
"dependencies": { | ||
"@travetto/cache": "0.x.x", | ||
"@travetto/di": "0.x.x", | ||
"@travetto/util": "0.x.x", | ||
"@types/file-type": "^5.2.0", | ||
"@types/gm": "^1.17.29", | ||
"@types/mime": "^1.3.1", | ||
"@types/os-tmpdir": "^1.0.0", | ||
"file-type": "^3.9.0", | ||
"gm": "^1.21.1", | ||
"mime": "^1.3.4", | ||
"mime-match": "^1.0.2", | ||
"os-tmpdir": "^1.0.1" | ||
}, | ||
"description": "", | ||
"@travetto/cache": "0.x.x", | ||
"@travetto/di": "0.x.x", | ||
"@travetto/util": "0.x.x", | ||
"@types/file-type": "^5.2.1", | ||
"@types/gm": "^1.17.33", | ||
"@types/mime": "^2.0.0", | ||
"@types/os-tmpdir": "^1.0.0", | ||
"file-type": "^7.6.0", | ||
"gm": "^1.23.1", | ||
"mime": "^2.2.0", | ||
"mime-match": "^1.0.2", | ||
"os-tmpdir": "^1.0.2" | ||
}, | ||
"description": "", | ||
"devDependencies": { | ||
"@travetto/test": "0.x.x" | ||
}, | ||
"license": "ISC", | ||
"main": "index.ts", | ||
"name": "@travetto/asset", | ||
}, | ||
"license": "ISC", | ||
"main": "index.ts", | ||
"name": "@travetto/asset", | ||
"repository": { | ||
"url": "https://github.com/travetto/asset.git" | ||
}, | ||
}, | ||
"scripts": { | ||
"test": "./node_modules/.bin/travetto-test.js" | ||
}, | ||
"version": "0.0.4" | ||
"test": "./node_modules/.bin/travetto-test" | ||
}, | ||
"version": "0.0.5" | ||
} |
import { AssetService, ImageService, AssetUtil, AssetSource, Asset } from '../../src'; | ||
import { timeout } from '@travetto/test'; | ||
import { expect } from 'chai'; | ||
import { Test, Suite, BeforeAll } from '@travetto/test'; | ||
import { DependencyRegistry, Injectable } from '@travetto/di'; | ||
import * as fs from 'fs'; | ||
import * as assert from 'assert'; | ||
import * as util from 'util'; | ||
@@ -42,21 +43,33 @@ @Injectable({ target: AssetSource }) | ||
describe('Asset Service', () => { | ||
it('downloads an file from a url', async () => { | ||
@Suite('Asset Service') | ||
class AssetTest { | ||
@BeforeAll() | ||
async init() { | ||
await DependencyRegistry.init(); | ||
} | ||
@Test('downloads an file from a url') | ||
async download() { | ||
let service = await DependencyRegistry.getInstance(AssetService); | ||
let filePath = await AssetUtil.downloadUrl('https://www.google.com/images/branding/googlelogo/2x/googlelogo_color_272x92dp.png'); | ||
expect(filePath).to.not.be.undefined; | ||
expect(filePath.split('.').pop()).equals('png'); | ||
assert(filePath !== undefined); | ||
assert(filePath.split('.').pop() === 'png'); | ||
let file = await AssetUtil.localFileToAsset(filePath); | ||
file = await service.save(file); | ||
expect(file.contentType).equals('image/png'); | ||
expect(file.length).is.greaterThan(0); | ||
fs.stat(filePath, (err, stats) => { | ||
expect(err).to.be.instanceof(Error); | ||
expect(stats).to.be.undefined; | ||
}); | ||
}); | ||
assert(file.contentType === 'image/png'); | ||
assert(file.length > 0); | ||
it('Test caching', timeout(10000, async () => { | ||
try { | ||
util.promisify(fs.stat)(filePath); | ||
} catch (err) { | ||
assert(err instanceof Error); | ||
} | ||
} | ||
@Test('Test caching') | ||
async cache() { | ||
let service = await DependencyRegistry.getInstance(AssetService); | ||
@@ -66,4 +79,4 @@ let imageService = await DependencyRegistry.getInstance(ImageService); | ||
let filePath = await AssetUtil.downloadUrl('https://image.freepik.com/free-icon/apple-logo_318-40184.jpg'); | ||
expect(filePath).to.not.be.undefined; | ||
expect(filePath.split('.').pop()).equals('jpeg'); | ||
assert(filePath !== undefined); | ||
assert(filePath.split('.').pop() === 'jpeg'); | ||
let file = await AssetUtil.localFileToAsset(filePath); | ||
@@ -73,3 +86,3 @@ file = await service.save(file, false, false); | ||
let asset = await service.get(file.filename); | ||
expect(asset).to.not.be.null; | ||
assert.ok(asset); | ||
@@ -84,4 +97,4 @@ let start = Date.now(); | ||
expect(diff2).to.be.lessThan(diff); | ||
})); | ||
}); | ||
assert(diff2 < diff); | ||
} | ||
} |
331
12805
14
+ Added@types/mime@2.0.3(transitive)
+ Addedfile-type@7.7.1(transitive)
+ Addedmime@2.6.0(transitive)
- Removed@types/mime@1.3.5(transitive)
- Removedfile-type@3.9.0(transitive)
- Removedmime@1.6.0(transitive)
Updated@types/file-type@^5.2.1
Updated@types/gm@^1.17.33
Updated@types/mime@^2.0.0
Updatedfile-type@^7.6.0
Updatedgm@^1.23.1
Updatedmime@^2.2.0
Updatedos-tmpdir@^1.0.2