smartcls/test/test.ts

47 lines
1.5 KiB
TypeScript
Raw Normal View History

2018-03-04 23:57:41 +00:00
import { expect, tap } from 'tapbundle';
import * as smartcls from '../ts/index';
import * as smartstring from 'smartstring';
2017-10-12 09:19:54 +00:00
2018-03-04 23:57:41 +00:00
smartcls.createNamespace('myspace');
let testNamespace = smartcls.getNamespace('myspace');
2017-10-12 09:19:54 +00:00
2018-03-04 23:57:41 +00:00
tap.testParallel('should get namespace', async tools => {
2017-10-12 09:19:54 +00:00
testNamespace.run(async () => {
2018-03-04 23:57:41 +00:00
testNamespace.set('some', 'anything');
await tools.delayFor(1000);
expect(testNamespace.get('some')).to.equal('anything');
2017-10-12 09:19:54 +00:00
tools.delayFor(200).then(() => {
2018-03-04 23:57:41 +00:00
expect(testNamespace.get('some')).to.equal('anything');
});
});
});
2017-10-12 09:19:54 +00:00
2018-03-04 23:57:41 +00:00
tap.testParallel('should get namespace with other values', async tools => {
2017-10-12 09:19:54 +00:00
testNamespace.run(async () => {
2018-03-04 23:57:41 +00:00
testNamespace.set('some', 'otherthing');
await tools.delayFor(500);
expect(testNamespace.get('some')).to.equal('otherthing');
2017-10-12 09:19:54 +00:00
tools.delayFor(200).then(() => {
2018-03-04 23:57:41 +00:00
expect(testNamespace.get('some')).to.equal('otherthing');
});
});
});
2017-10-12 09:19:54 +00:00
2018-03-04 23:57:41 +00:00
tap.test('should not expose memory leak', async tools => {
let testArray = [];
2017-10-12 09:19:54 +00:00
await tools.checkIterationLeak(async () => {
testNamespace.run(async () => {
2018-03-04 23:57:41 +00:00
let randomLargeString = smartstring.create.createRandomString('*', 10000, {});
2017-10-12 09:19:54 +00:00
// testArray.push(randomLargeString) // trigger memory leak
2018-03-04 23:57:41 +00:00
testNamespace.set('some', randomLargeString);
await tools.delayFor(10);
expect(testNamespace.get('some')).to.equal(randomLargeString);
2017-10-12 09:19:54 +00:00
tools.delayFor(10).then(() => {
2018-03-04 23:57:41 +00:00
expect(testNamespace.get('some')).to.equal(randomLargeString);
});
});
});
});
2017-10-12 09:19:54 +00:00
2018-03-04 23:57:41 +00:00
tap.start();