diff --git a/jest.config.mjs b/jest.config.mjs deleted file mode 100644 index be3e931..0000000 --- a/jest.config.mjs +++ /dev/null @@ -1,8 +0,0 @@ -/** @type {import('jest').Config} */ -const config = { - transform: { - "^.+\\.tsx?$": "esbuild-jest", - }, -} - -export default config diff --git a/package.json b/package.json index be76adf..6d2f066 100644 --- a/package.json +++ b/package.json @@ -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", @@ -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": { diff --git a/__tests__/auth.api_key.ts b/test/auth.api_key.ts similarity index 97% rename from __tests__/auth.api_key.ts rename to test/auth.api_key.ts index 23f2075..5d23fd1 100644 --- a/__tests__/auth.api_key.ts +++ b/test/auth.api_key.ts @@ -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" diff --git a/__tests__/auth.oauth.ts b/test/auth.oauth.ts similarity index 92% rename from __tests__/auth.oauth.ts rename to test/auth.oauth.ts index a57aa55..e8759d2 100644 --- a/__tests__/auth.oauth.ts +++ b/test/auth.oauth.ts @@ -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" @@ -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() diff --git a/__tests__/flickr.ts b/test/flickr.ts similarity index 95% rename from __tests__/flickr.ts rename to test/flickr.ts index 5068d30..21543f4 100644 --- a/__tests__/flickr.ts +++ b/test/flickr.ts @@ -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" diff --git a/__tests__/oauth.ts b/test/oauth.ts similarity index 92% rename from __tests__/oauth.ts rename to test/oauth.ts index a54c9df..d670a43 100644 --- a/__tests__/oauth.ts +++ b/test/oauth.ts @@ -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" @@ -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 () { @@ -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 () { @@ -54,7 +56,7 @@ describe("OAuth", function () { describe("#nonce", function () { beforeEach(function () { - jest.restoreAllMocks() + mock.restoreAll() }) it("returns a string", function () { diff --git a/__tests__/params.ts b/test/params.ts similarity index 94% rename from __tests__/params.ts rename to test/params.ts index 0e50a07..278caf9 100644 --- a/__tests__/params.ts +++ b/test/params.ts @@ -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" diff --git a/__tests__/parser.form.ts b/test/parser.form.ts similarity index 90% rename from __tests__/parser.form.ts rename to test/parser.form.ts index eff493b..f266001 100644 --- a/__tests__/parser.form.ts +++ b/test/parser.form.ts @@ -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" diff --git a/__tests__/parser.json.ts b/test/parser.json.ts similarity index 90% rename from __tests__/parser.json.ts rename to test/parser.json.ts index e597713..0c6b2c2 100644 --- a/__tests__/parser.json.ts +++ b/test/parser.json.ts @@ -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" diff --git a/__tests__/parser.xml.ts b/test/parser.xml.ts similarity index 96% rename from __tests__/parser.xml.ts rename to test/parser.xml.ts index a7a56d6..c49ec65 100644 --- a/__tests__/parser.xml.ts +++ b/test/parser.xml.ts @@ -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" diff --git a/__tests__/services.oauth.ts b/test/services.oauth.ts similarity index 96% rename from __tests__/services.oauth.ts rename to test/services.oauth.ts index 6d419b1..0630c0c 100644 --- a/__tests__/services.oauth.ts +++ b/test/services.oauth.ts @@ -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" diff --git a/__tests__/services.replace.ts b/test/services.replace.ts similarity index 96% rename from __tests__/services.replace.ts rename to test/services.replace.ts index 47b038b..797b698 100644 --- a/__tests__/services.replace.ts +++ b/test/services.replace.ts @@ -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" diff --git a/__tests__/services.rest.ts b/test/services.rest.ts similarity index 84% rename from __tests__/services.rest.ts rename to test/services.rest.ts index 23805d7..be4ab8f 100644 --- a/__tests__/services.rest.ts +++ b/test/services.rest.ts @@ -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" @@ -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 () { @@ -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 () { @@ -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) }) }) }) diff --git a/__tests__/services.upload.ts b/test/services.upload.ts similarity index 96% rename from __tests__/services.upload.ts rename to test/services.upload.ts index 6827f5f..675f485 100644 --- a/__tests__/services.upload.ts +++ b/test/services.upload.ts @@ -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" diff --git a/__tests__/transport.fetch.ts b/test/transport.fetch.ts similarity index 78% rename from __tests__/transport.fetch.ts rename to test/transport.fetch.ts index b37f045..22c5fed 100644 --- a/__tests__/transport.fetch.ts +++ b/test/transport.fetch.ts @@ -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" @@ -9,9 +9,7 @@ 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() @@ -19,9 +17,9 @@ describe("transport/fetch", function () { 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") @@ -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") @@ -53,9 +49,7 @@ 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() @@ -63,9 +57,9 @@ describe("transport/fetch", function () { 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") @@ -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")