Comments (6)
So I tried fixing this
runTests = async (): Promise<void> => {
const promises: Promise<void>[] = [];
this.tests.forEach((test) => {
// wait for both beforeEachs and test.func
const promise = Promise.all(this.beforeEachs.map((f) => f())).then(() =>
test.func()
);
promises.push(promise);
Deno.test(`[${this.prefix}] ${test.name}`, () => {
return promise;
});
});
try {
await Promise.allSettled(promises);
} finally {
this.afterAlls.forEach(async (f) => await f());
}
};
But the order of execution is not as expected
OK
OK
running 2 tests
test [command] set ... ok (2ms)
test [command] keys ... FAILED (0ms)
The "OK" is from client.flushdb
. They are executed before all tests are run. pinging @uki00a for thoughts on how to resolve this 😅. Thanks in advance!
from redis.
How about the following?
runTests = async (): Promise<void> => {
const promises: Promise<void>[] = [];
const defineTest = (test: { name: string, func: TestFunc }) => {
Deno.test(`[${this.prefix}] ${test.name}`, () => {
// wait for both beforeEachs and test.func
const promise = this.beforeEachs.reduce(async (p, f) => {
await p;
return f();
}, Promise.resolve()).then(() => test.func());
promises.push(promise);
return promise;
});
};
this.tests.forEach(defineTest);
try {
await Promise.allSettled(promises);
} finally {
this.afterAlls.forEach(async (f) => await f());
}
};
Diff:
runTests = async (): Promise<void> => {
const promises: Promise<void>[] = [];
- this.tests.forEach((test) => {
- // wait for both beforeEachs and test.func
- const promise = Promise.all(this.beforeEachs.map((f) => f())).then(() =>
- test.func()
- );
- promises.push(promise);
+
+ const defineTest = (test: { name: string, func: TestFunc }) => {
Deno.test(`[${this.prefix}] ${test.name}`, () => {
+ // wait for both beforeEachs and test.func
+ const promise = this.beforeEachs.reduce(async (p, f) => {
+ await p;
+ return f();
+ }, Promise.resolve()).then(() => test.func());
+ promises.push(promise);
return promise;
});
- });
+ };
+
+ this.tests.forEach(defineTest);
try {
await Promise.allSettled(promises);
} finally {
from redis.
I still got BadResource, which means client is closed before the beforeEach
promise resolves
from redis.
Actually by putting the promises.push()
inside Deno.test, it's run asynchronously and so if you log promises
after tests.forEach
it's empty
from redis.
OK, so how about the following code? (deferred()
is exported in vendor/https/deno.land/std/async/mod.ts
)
runTests = async (): Promise<void> => {
const promises: Promise<void>[] = [];
const defineTest = (test: { name: string, func: TestFunc }) => {
const promise = deferred<void>();
promises.push(promise);
Deno.test(`[${this.prefix}] ${test.name}`, async () => {
try {
// wait for both beforeEachs and test.func
await this.beforeEachs.reduce(async (p, f) => {
await p;
return f();
}, Promise.resolve()).then(() => test.func());
promise.resolve();
} catch (e) {
promise.reject(e);
}
return promise;
});
};
this.tests.forEach(defineTest);
try {
await Promise.allSettled(promises);
} finally {
this.afterAlls.forEach(async (f) => await f());
}
};
Diff:
const promises: Promise<void>[] = [];
const defineTest = (test: { name: string, func: TestFunc }) => {
- Deno.test(`[${this.prefix}] ${test.name}`, () => {
- // wait for both beforeEachs and test.func
- const promise = this.beforeEachs.reduce(async (p, f) => {
- await p;
- return f();
- }, Promise.resolve()).then(() => test.func());
- promises.push(promise);
+ const promise = deferred<void>();
+ promises.push(promise);
+ Deno.test(`[${this.prefix}] ${test.name}`, async () => {
+ try {
+ // wait for both beforeEachs and test.func
+ await this.beforeEachs.reduce(async (p, f) => {
+ await p;
+ return f();
+ }, Promise.resolve()).then(() => test.func());
+ promise.resolve();
+ } catch (e) {
+ promise.reject(e);
+ }
return promise;
});
};
from redis.
The above didn't work either...
So after a few hours this is what I came up with, a little hacky but works. This ensures that beforeEach and tests are run sequentially.
runTests = async (): Promise<void> => {
try {
for (const test of this.tests) {
let res: void | Error;
try {
res = await this.beforeEachs
.reduce((p, f) => p.then(f), Promise.resolve())
.then(test.func);
} catch (err) {
res = err;
}
Deno.test(`[${this.prefix}] ${test.name}`, () => {
if (res instanceof Error) {
throw res;
}
});
}
} finally {
this.afterAlls.forEach(async (f) => await f());
}
};
from redis.
Related Issues (20)
- Suggestion: Use docker-based redis for tests
- BREAKING: Rename `withScore` to `withScores`
- Re-enable `deno task make_mod` in CI
- BulkNil and execArrayReply breaking xread
- PubSub with binary messages HOT 1
- [feat] keepalive feature
- [feat] automatically reconnect when interrupted
- Bug: xrange failed to parse empty string
- deps: import `cluster-key-slot` and `lodash-es` from esm.sh
- Support for RedisJson - JSON.GET
- Support AbortController in a client HOT 1
- Watch vs tx HOT 1
- Subscribe / psubscribe hangs after calling sub.receive() HOT 1
- `Redis.scan` cursor parameter requires a number
- sendCommand api inconsistency HOT 1
- Property 'set' does not exist on type 'Redis'.deno-ts(2339) HOT 5
- Parallel Request Issue HOT 1
- Subscribe, unsubscribe, resubscribe HOT 4
- feat: Auto-pipelining
- feat: Connection pooling
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from redis.