Skip to content

Commit

Permalink
chore(cookie-jar): Add test script and a few more tests (#11856)
Browse files Browse the repository at this point in the history
  • Loading branch information
Tobbe committed Jan 16, 2025
1 parent e1378d4 commit 462cc4b
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 2 deletions.
6 changes: 4 additions & 2 deletions packages/cookie-jar/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@
"scripts": {
"build": "tsx ./build.mts && run build:types",
"build:pack": "yarn pack -o redwoodjs-cookie-jar.tgz",
"build:types": "tsc --build --verbose"
"build:types": "tsc --build --verbose",
"test": "vitest run"
},
"dependencies": {
"cookie": "0.7.2",
Expand All @@ -31,7 +32,8 @@
"@redwoodjs/framework-tools": "workspace:*",
"@types/fs-extra": "11.0.4",
"tsx": "4.19.2",
"typescript": "5.6.2"
"typescript": "5.6.2",
"vitest": "2.0.5"
},
"gitHead": "3905ed045508b861b495f8d5630d76c7a157d8f1"
}
21 changes: 21 additions & 0 deletions packages/cookie-jar/src/CookieJar.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,27 @@ describe('CookieJar', () => {
expect(cookieJar.get('tz')).toStrictEqual('Asia/Bangkok')
})

test('instatiation behavior with invalid string', () => {
expect(new CookieJar('; session').get('foo')).toBeUndefined()
expect(new CookieJar('; session').get('session')).toBeUndefined()
expect(new CookieJar('session').get('session')).toBeUndefined()
expect(new CookieJar('; session=woof-1234').get('session')).toEqual(
'woof-1234',
)
expect(new CookieJar('kittens; session=woof-1234').get('session')).toEqual(
'woof-1234',
)
expect(
new CookieJar('kittens; session=woof-1234').get('kittens'),
).toBeUndefined()
expect(
new CookieJar('kittens; session=woof-1234; foo').get('foo'),
).toBeUndefined()
expect(
new CookieJar('kittens; session=woof-1234; foo=').get('foo'),
).toEqual('')
})

test('getWithOptions', () => {
const jar = new CookieJar()
jar.set('kittens', 'soft', { path: '/bazinga' })
Expand Down
1 change: 1 addition & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -8345,6 +8345,7 @@ __metadata:
fs-extra: "npm:11.2.0"
tsx: "npm:4.19.2"
typescript: "npm:5.6.2"
vitest: "npm:2.0.5"
languageName: unknown
linkType: soft

Expand Down

0 comments on commit 462cc4b

Please sign in to comment.