import * as chai from 'chai'; import * as chaiAsPromised from 'chai-as-promised'; import 'mocha'; chai.use(chaiAsPromised); const expect = chai.expect; import {Asset} from './asset'; const files = { "boop": { fiz: 1, bar: {} }, 'foo.toml': `fiz = 5 [bar] beep = 5`, 'foo-is.toml': `is = 'foo.toml' [bar] deep = 6 `, 'foo-is-is.toml': `is ='foo-is.toml' [beep] something = 'else' `, 'has-foo.toml': ` fiver = 5 [boop] deep = [0, 0, 0] [has.foo1] is = 'foo-is.toml'`, 'is-has-foo.toml': `is = 'has-foo.toml' fiver = 6 [has.foo1] fiz = 6 add = false [has.foo2] is = 'foo-is-is.toml' `, 'array-test.toml': `foop = [0, 0, 0]` }; let messageHandler; Asset.initialize((onMessage) => { messageHandler = onMessage; }, (file: string) => { return Promise.resolve(files[file]); }); describe('Assets', () => { it('should get a file', () => expect(Asset.get('boop')).to.eventually.deep.equal({ fiz: 1, bar: {} }) ); it('should get a toml file', () => expect(Asset.get('foo.toml')).to.eventually.deep.equal({ fiz: 5, bar: { beep: 5 } }) ); it('should upgrade a toml files is', () => expect(Asset.get('foo-is.toml')).to.eventually.deep.equal({ is: 'foo.toml', fiz: 5, bar: { beep: 5, deep: 6 } }) ); it('should upgrade arbitrarily deep toml files is', () => expect(Asset.get('foo-is-is.toml')).to.eventually.deep.equal({ is: 'foo-is.toml', fiz: 5, bar: { beep: 5, deep: 6 }, beep: { something: 'else' } }) ); it('should expand has', () => expect(Asset.get('has-foo.toml')).to.eventually.deep.equal({ fiver: 5, boop: { deep: [0, 0, 0] }, has: { foo1: { is: 'foo-is.toml', fiz: 5, bar: { beep: 5, deep: 6 } } } }) ); it('should merge has for is and expand them', () => expect(Asset.get('is-has-foo.toml')).to.eventually.deep.equal({ is: 'has-foo.toml', fiver: 6, boop: { deep: [0, 0, 0] }, has: { foo1: { is: 'foo-is.toml', fiz: 6, bar: { beep: 5, deep: 6 }, add: false }, foo2: { is: 'foo-is-is.toml', fiz: 5, bar: { beep: 5, deep: 6 }, beep: { something: 'else' } } } }) ); it('should handle arrays okay', () => expect(Asset.get('array-test.toml')).to.eventually.deep.equal({ foop: [0, 0, 0] }) ); });