Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 0 additions & 8 deletions jest.config.mjs

This file was deleted.

6 changes: 2 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
"build-cjs": "esbuild --bundle --outfile=dist/index.cjs --platform=node --format=cjs src/index.ts",
"build-esm": "esbuild --bundle --outfile=dist/index.mjs --platform=node --format=esm src/index.ts",
"build-browser": "esbuild --bundle --outfile=dist/index.js --format=esm src/index.ts",
"test": "jest"
"test": "node --import tsx --test test/*.ts"
},
"repository": {
"type": "git",
Expand All @@ -67,16 +67,14 @@
},
"homepage": "https://github.com/flickr/flickr-sdk#readme",
"devDependencies": {
"@jest/globals": "^29.7.0",
"@types/node": "^20.8.4",
"esbuild": "^0.19.4",
"esbuild-jest": "^0.5.0",
"flickr-sdk": "file:.",
"jest": "^29.7.0",
"min-qs": "^1.4.0",
"min-url": "^1.5.0",
"prettier": "^3.0.3",
"stringlist-regexp": "^1.0.2",
"tsx": "^4.20.3",
"typescript": "^5.2.2"
},
"dependencies": {
Expand Down
2 changes: 1 addition & 1 deletion __tests__/auth.api_key.ts → test/auth.api_key.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { describe, it } from "@jest/globals"
import { describe, it } from "node:test"
import * as assert from "node:assert"
import { APIKeyAuth } from "flickr-sdk"

Expand Down
12 changes: 5 additions & 7 deletions __tests__/auth.oauth.ts → test/auth.oauth.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { jest, describe, it } from "@jest/globals"
import { describe, it, mock } from "node:test"
import * as assert from "node:assert"
import { OAuthAuth } from "flickr-sdk"

Expand Down Expand Up @@ -77,21 +77,19 @@ describe("auth/oauth", function () {
"oauth token secret",
)

jest
.spyOn(
mock.method(
// @ts-expect-error
auth.oauth,
"timestamp",
() => "499166400"
)
.mockReturnValue("499166400")

jest
.spyOn(
mock.method(
// @ts-expect-error
auth.oauth,
"nonce",
() => "p2m2bnHdXVIsQH0FUv0oN9XrJU57ak7dSSpHU36mn4k="
)
.mockReturnValue("p2m2bnHdXVIsQH0FUv0oN9XrJU57ak7dSSpHU36mn4k=")

const params = new Map()

Expand Down
2 changes: 1 addition & 1 deletion __tests__/flickr.ts → test/flickr.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { describe, it } from "@jest/globals"
import { describe, it } from "node:test"
import * as assert from "node:assert"
import { createFlickr } from "flickr-sdk"

Expand Down
16 changes: 9 additions & 7 deletions __tests__/oauth.ts → test/oauth.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { jest, describe, it, beforeEach } from "@jest/globals"
import { describe, it, beforeEach, mock } from "node:test"
import * as assert from "node:assert"
import { OAuth } from "flickr-sdk"

Expand All @@ -7,11 +7,13 @@ describe("OAuth", function () {

beforeEach(function () {
oauth = new OAuth("consumer key", "consumer secret")
jest.spyOn(oauth, "timestamp").mockReturnValue("499166400")
mock.method(oauth, "timestamp", () => "499166400")

jest
.spyOn(oauth, "nonce")
.mockReturnValue("p2m2bnHdXVIsQH0FUv0oN9XrJU57ak7dSSpHU36mn4k=")
mock.method(
oauth,
"nonce",
() => "p2m2bnHdXVIsQH0FUv0oN9XrJU57ak7dSSpHU36mn4k=",
)
})

it('requires "consumerKey" and "consumerSecret"', function () {
Expand Down Expand Up @@ -44,7 +46,7 @@ describe("OAuth", function () {

describe("#timestamp", function () {
beforeEach(function () {
jest.restoreAllMocks()
mock.restoreAll()
})

it("returns the current system time in seconds", function () {
Expand All @@ -54,7 +56,7 @@ describe("OAuth", function () {

describe("#nonce", function () {
beforeEach(function () {
jest.restoreAllMocks()
mock.restoreAll()
})

it("returns a string", function () {
Expand Down
2 changes: 1 addition & 1 deletion __tests__/params.ts → test/params.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { describe, it } from "@jest/globals"
import { describe, it } from "node:test"
import * as assert from "node:assert"
import { GET, POST } from "flickr-sdk"

Expand Down
2 changes: 1 addition & 1 deletion __tests__/parser.form.ts → test/parser.form.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { describe, it } from "@jest/globals"
import { describe, it } from "node:test"
import * as assert from "node:assert"
import { FormParser } from "flickr-sdk"

Expand Down
2 changes: 1 addition & 1 deletion __tests__/parser.json.ts → test/parser.json.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { describe, it } from "@jest/globals"
import { describe, it } from "node:test"
import * as assert from "node:assert"
import { JSONParser } from "flickr-sdk"

Expand Down
2 changes: 1 addition & 1 deletion __tests__/parser.xml.ts → test/parser.xml.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { describe, it } from "@jest/globals"
import { describe, it } from "node:test"
import * as assert from "node:assert"
import { XMLParser } from "flickr-sdk"

Expand Down
2 changes: 1 addition & 1 deletion __tests__/services.oauth.ts → test/services.oauth.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { describe, it } from "@jest/globals"
import { describe, it } from "node:test"
import { MockTransport, NullAuth, OAuthService } from "flickr-sdk"
import * as assert from "node:assert"

Expand Down
2 changes: 1 addition & 1 deletion __tests__/services.replace.ts → test/services.replace.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { describe, it } from "@jest/globals"
import { describe, it } from "node:test"
import * as assert from "node:assert"
import { ReplaceService, NullAuth, MockTransport } from "flickr-sdk"

Expand Down
14 changes: 7 additions & 7 deletions __tests__/services.rest.ts → test/services.rest.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { jest, describe, it } from "@jest/globals"
import { describe, it, mock } from "node:test"
import * as assert from "node:assert"
import { FlickrService, MockTransport, NullAuth } from "flickr-sdk"

Expand Down Expand Up @@ -44,12 +44,12 @@ describe("FlickrService", function () {
stat: "ok",
})

const get = jest.spyOn(transport, "get")
const get = mock.method(transport, "get")

const service = new FlickrService(transport, auth)
await service.call("flickr.test.echo", { foo: "bar" })

assert.strictEqual(get.mock.calls.length, 1)
assert.strictEqual(get.mock.callCount(), 1)
})

it("makes a POST request for a write method", async function () {
Expand All @@ -59,12 +59,12 @@ describe("FlickrService", function () {
stat: "ok",
})

const post = jest.spyOn(transport, "post")
const post = mock.method(transport, "post")

const service = new FlickrService(transport, auth)
await service.call("flickr.photosets.editPhotos", { foo: "bar" })

assert.strictEqual(post.mock.calls.length, 1)
assert.strictEqual(post.mock.callCount(), 1)
})

it("makes a POST request for a delete method", async function () {
Expand All @@ -73,12 +73,12 @@ describe("FlickrService", function () {
stat: "ok",
})

const post = jest.spyOn(transport, "post")
const post = mock.method(transport, "post")

const service = new FlickrService(transport, auth)
await service.call("flickr.photosets.delete", { foo: "bar" })

assert.strictEqual(post.mock.calls.length, 1)
assert.strictEqual(post.mock.callCount(), 1)
})
})
})
2 changes: 1 addition & 1 deletion __tests__/services.upload.ts → test/services.upload.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { describe, it } from "@jest/globals"
import { describe, it } from "node:test"
import * as assert from "node:assert"
import { MockTransport, NullAuth, UploadService } from "flickr-sdk"

Expand Down
34 changes: 13 additions & 21 deletions __tests__/transport.fetch.ts → test/transport.fetch.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { jest, afterEach, describe, it } from "@jest/globals"
import { afterEach, describe, it, mock } from "node:test"
import * as assert from "node:assert"
import { FetchTransport, GET, POST } from "flickr-sdk"
import { createServer } from "node:http"
Expand All @@ -9,19 +9,17 @@ describe("transport/fetch", function () {
it("makes a GET fetch request", async function () {
const transport = new FetchTransport()

const fn = jest
.spyOn(transport, "fetch")
.mockResolvedValue(new Response())
const fn = mock.method(transport, "fetch", async () => new Response())

const params = new GET()

params.set("foo", "bar")

await transport.get("http://example.com/foo", params)

assert.strictEqual(fn.mock.calls.length, 1)
assert.strictEqual(fn.mock.callCount(), 1)

const [url, init] = fn.mock.calls[0]
const [url, init] = fn.mock.calls[0].arguments

assert.strictEqual(url, "http://example.com/foo?foo=bar")
assert.strictEqual(init.method, "GET")
Expand All @@ -34,15 +32,13 @@ describe("transport/fetch", function () {
},
})

const fn = jest
.spyOn(transport, "fetch")
.mockResolvedValue(new Response())
const fn = mock.method(transport, "fetch", async () => new Response())

await transport.get("http://example.com/foo")

assert.strictEqual(fn.mock.calls.length, 1)
assert.strictEqual(fn.mock.callCount(), 1)

const [url, init] = fn.mock.calls[0]
const [url, init] = fn.mock.calls[0].arguments

// @ts-ignore
assert.strictEqual(init.headers.cookie, "foo")
Expand All @@ -53,19 +49,17 @@ describe("transport/fetch", function () {
it("makes a POST fetch request", async function () {
const transport = new FetchTransport()

const fn = jest
.spyOn(transport, "fetch")
.mockResolvedValue(new Response())
const fn = mock.method(transport, "fetch", async () => new Response())

const params = new POST()

params.set("foo", "bar")

await transport.post("http://example.com/foo", params)

assert.strictEqual(fn.mock.calls.length, 1)
assert.strictEqual(fn.mock.callCount(), 1)

const [url, init] = fn.mock.calls[0]
const [url, init] = fn.mock.calls[0].arguments

assert.strictEqual(url, "http://example.com/foo")
assert.strictEqual(init.method, "POST")
Expand All @@ -80,15 +74,13 @@ describe("transport/fetch", function () {
},
})

const fn = jest
.spyOn(transport, "fetch")
.mockResolvedValue(new Response())
const fn = mock.method(transport, "fetch", async () => new Response())

await transport.post("http://example.com/foo")

assert.strictEqual(fn.mock.calls.length, 1)
assert.strictEqual(fn.mock.callCount(), 1)

const [url, init] = fn.mock.calls[0]
const [_, init] = fn.mock.calls[0].arguments

// @ts-ignore
assert.strictEqual(init.headers.cookie, "foo")
Expand Down