f5976a2d74
* feat: moved tl-runtime to esm and native ArrayBuffers * feat: migration to esm * fix(core): web-related fixes * test: finally, some good fucking e2e * chore: fixed linters etc * ci: added e2e to ci * build(tl): fixed gen-code on node 20 * fix: codegen Uint8Array, not Buffer never `git reset --hard` kids * build: only do type-aware linting for `packages/*` * build: ignore no-unresolved in ci for e2e * fix: node 16 doesn't have subtle crypto apparently? * fix(tests): use Uint8Array for gods sake please can i just merge this already * ci: don't parallel tasks in ci because machines are utter garbage and it may just randomly break * ci: pass secrets to e2e tests * ci: separate cli command for ci apparently im retarded * fix: run codegen in e2e im actually retarded * ci: more fixes for e2e * ci: debugging stuff * ci: still debugging * ci: hopefully fix ci???
74 lines
1.7 KiB
TypeScript
74 lines
1.7 KiB
TypeScript
import { expect } from 'chai'
|
|
import { describe, it } from 'mocha'
|
|
|
|
import { memoizeGetters } from '../src/utils/memoize.js'
|
|
|
|
describe('memoizeGetters', () => {
|
|
it('should memoize getters', () => {
|
|
class Test {
|
|
private _value = 0
|
|
|
|
get value() {
|
|
return this._value++
|
|
}
|
|
}
|
|
memoizeGetters(Test, ['value'])
|
|
|
|
const test = new Test()
|
|
|
|
expect(test.value).to.equal(0)
|
|
expect(test.value).to.equal(0)
|
|
expect(test.value).to.equal(0)
|
|
})
|
|
|
|
it('should not share state across multiple instances', () => {
|
|
class Test {
|
|
get value() {
|
|
return Math.random()
|
|
}
|
|
}
|
|
|
|
memoizeGetters(Test, ['value'])
|
|
|
|
const test1 = new Test()
|
|
const test2 = new Test()
|
|
|
|
const val = test1.value
|
|
expect(test1.value).to.equal(val)
|
|
expect(test2.value).to.not.equal(val)
|
|
})
|
|
|
|
it('should only memoize the specified getters', () => {
|
|
class Test {
|
|
get memoized() {
|
|
return Math.random()
|
|
}
|
|
|
|
get other() {
|
|
return Math.random()
|
|
}
|
|
}
|
|
|
|
memoizeGetters(Test, ['memoized'])
|
|
|
|
const test = new Test()
|
|
|
|
expect(test.memoized).to.equal(test.memoized)
|
|
expect(test.other).to.not.equal(test.other)
|
|
})
|
|
|
|
it('should propagate errors', () => {
|
|
class Test {
|
|
get value() {
|
|
throw new Error('test')
|
|
}
|
|
}
|
|
|
|
memoizeGetters(Test, ['value'])
|
|
|
|
const test = new Test()
|
|
|
|
expect(() => test.value).to.throw('test')
|
|
expect(() => test.value).to.throw('test')
|
|
})
|
|
})
|