1
- import kv , { VercelKV , createClient } from '.' ;
1
+ import defaultKv , { kv , VercelKV , createClient } from '.' ;
2
2
3
3
let scanReturnValues : [ number , string [ ] ] [ ] = [ [ 0 , [ ] ] ] ;
4
4
jest . mock ( '@upstash/redis' , ( ) => ( {
@@ -15,10 +15,11 @@ jest.mock('@upstash/redis', () => ({
15
15
describe ( '@vercel/kv' , ( ) => {
16
16
beforeEach ( ( ) => {
17
17
scanReturnValues = [ [ 0 , [ ] ] ] ;
18
+ jest . clearAllMocks ( ) ;
18
19
} ) ;
19
20
20
21
describe ( 'kv export' , ( ) => {
21
- it ( 'exports a default client' , async ( ) => {
22
+ it ( 'exports "kv" client' , async ( ) => {
22
23
process . env . KV_REST_API_URL =
23
24
'https://foobar-6739.redis.vercel-storage.com' ;
24
25
process . env . KV_REST_API_TOKEN = 'tok_foobar' ;
@@ -28,6 +29,30 @@ describe('@vercel/kv', () => {
28
29
process . env . KV_REST_API_URL = undefined ;
29
30
process . env . KV_REST_API_TOKEN = undefined ;
30
31
} ) ;
32
+
33
+ it ( 'exports default legacy client' , async ( ) => {
34
+ process . env . KV_REST_API_URL =
35
+ 'https://foobar-6739.redis.vercel-storage.com' ;
36
+ process . env . KV_REST_API_TOKEN = 'tok_foobar' ;
37
+
38
+ expect ( await defaultKv . get ( 'foo' ) ) . toEqual ( 'bar' ) ;
39
+
40
+ process . env . KV_REST_API_URL = undefined ;
41
+ process . env . KV_REST_API_TOKEN = undefined ;
42
+ } ) ;
43
+
44
+ it ( 'should load awaited default module (Vite use case' , async ( ) => {
45
+ const kvModule = await import ( '.' ) . then ( ( m ) => m . default ) ;
46
+
47
+ process . env . KV_REST_API_URL =
48
+ 'https://foobar-6739.redis.vercel-storage.com' ;
49
+ process . env . KV_REST_API_TOKEN = 'tok_foobar' ;
50
+
51
+ expect ( await kvModule . get ( 'foo' ) ) . toEqual ( 'bar' ) ;
52
+
53
+ process . env . KV_REST_API_URL = undefined ;
54
+ process . env . KV_REST_API_TOKEN = undefined ;
55
+ } ) ;
31
56
} ) ;
32
57
33
58
describe ( 'createClient' , ( ) => {
1 commit comments
vercel[bot] commentedon May 11, 2023
Successfully deployed to the following URLs:
vercel-storage-next-integration-test-suite – ./
vercel-storage-next-integration-test-s-git-14bcac-curated-tests.vercel.app
vercel-storage-next-integration-test-suite-curated-tests.vercel.app
storage-rho.vercel.app