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
385 changes: 0 additions & 385 deletions package-lock.json

Large diffs are not rendered by default.

6 changes: 2 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,14 @@
"prepare": "npm run build",
"lint": "oxlint --deny-warnings",
"types": "tsc --noEmit",
"unit": "cross-env MODE=test tsdown --logLevel=warn && vitest run",
"unit:watch": "concurrently --raw --kill-others \"cross-env MODE=test tsdown --watch --logLevel=warn\" \"vitest watch\"",
"unit": "vitest run",
"unit:watch": "vitest watch",
"test": "npm run lint && npm run types && npm run unit"
},
"devDependencies": {
"@prismicio/types-internal": "3.16.1",
"@types/node": "25.0.9",
"change-case": "5.4.4",
"concurrently": "^9.2.1",
"cross-env": "^10.1.0",
"dedent": "^1.7.2",
"detect-indent": "^7.0.2",
"github-slugger": "2.0.0",
Expand Down
2 changes: 1 addition & 1 deletion src/commands/sync.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { resolveEnvironment } from "../lib/prismic/environments";
import { getRepositoryName } from "../project";
import { trackCommandStart, trackCommandEnd } from "../tracking";

const POLL_INTERVAL_MS = env.TEST ? 500 : 5000;
const POLL_INTERVAL_MS = env.PRISMIC_SYNC_POLL_MS ?? 5000;
const MAX_CONSECUTIVE_ERRORS = 5;

const config = {
Expand Down
7 changes: 1 addition & 6 deletions src/env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,7 @@ const DEFAULT_PRISMIC_SENTRY_DSN =
export const DEFAULT_PRISMIC_HOST = "prismic.io";

const Env = z.object({
MODE: z.string(),
DEV: z.stringbool(),
PROD: z.stringbool(),
TEST: z.stringbool(),
PRISMIC_SENTRY_DSN: z._default(z.httpUrl(), DEFAULT_PRISMIC_SENTRY_DSN),
PRISMIC_SENTRY_ENVIRONMENT: z.optional(z.string()),
PRISMIC_SENTRY_ENABLED: z.optional(z.stringbool()),
Expand All @@ -19,12 +16,10 @@ const Env = z.object({
PRISMIC_DOCS_HOST: z.optional(z.string()),
PRISMIC_CONFIG_DIR: z.optional(z.string()),
PRISMIC_TYPE_BUILDER_ENABLED: z.optional(z.stringbool()),
PRISMIC_SYNC_POLL_MS: z.optional(z.coerce.number().check(z.gte(100))),
});

export const env = z.parse(Env, {
...process.env,
MODE: process.env.MODE,
DEV: process.env.DEV,
PROD: process.env.PROD,
TEST: process.env.TEST,
});
1 change: 1 addition & 0 deletions test/it.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ export const it = test.extend<Fixtures>({
PRISMIC_TYPE_BUILDER_ENABLED: "true",
PRISMIC_SENTRY_ENABLED: "false",
PRISMIC_TELEMETRY_ENABLED: "false",
PRISMIC_SYNC_POLL_MS: "500",
NO_UPDATE_NOTIFIER: "1",
PRISMIC_CONFIG_DIR: fileURLToPath(configDir),
...options?.nodeOptions?.env,
Expand Down
21 changes: 17 additions & 4 deletions test/setup.global.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,28 @@
import type { Vitest } from "vitest/node";
import type { TestProject } from "vitest/node";

import { build, type InlineConfig } from "tsdown";

import { upsertLocale, createRepository, deleteRepository, login } from "./prismic";

const TSDOWN_TEST_CONFIG: InlineConfig = {
logLevel: "silent",
unbundle: true,
minify: false,
};

declare module "vitest" {
export interface ProvidedContext {
token: string;
repo: string;
}
}

export default async function ({ provide }: Vitest): Promise<() => Promise<void>> {
export default async function (project: TestProject): Promise<() => Promise<void>> {
await build(TSDOWN_TEST_CONFIG);
project.onTestsRerun(async () => {
await build(TSDOWN_TEST_CONFIG);
});

try {
process.loadEnvFile(".env.test.local");
} catch {
Expand All @@ -24,13 +37,13 @@ export default async function ({ provide }: Vitest): Promise<() => Promise<void>

console.info(`Logging in to ${host} with ${email}`);
const token = await login(email, password, { host });
provide("token", token);
project.provide("token", token);

const repo = `prismic-cli-test-${crypto.randomUUID().replace(/-/g, "").slice(0, 8)}`;
console.info(`Creating shared test repository: ${repo}`);
await createRepository(repo, { token, host });
await upsertLocale("en-us", { isMaster: true, repo, token, host });
provide("repo", repo);
project.provide("repo", repo);

return async () => {
try {
Expand Down
11 changes: 3 additions & 8 deletions tsdown.config.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { defineConfig } from "tsdown";

const MODE = process.env.MODE || "development";
const TEST = MODE === "test";
const PROD = process.env.MODE === "production";

export default defineConfig({
entry: {
Expand All @@ -12,13 +11,9 @@ export default defineConfig({
},
format: "esm",
platform: "node",
unbundle: TEST,
minify: !TEST,
minify: true,
envPrefix: "PRISMIC_",
define: {
"process.env.MODE": JSON.stringify(MODE),
"process.env.DEV": JSON.stringify(String(MODE !== "production")),
"process.env.PROD": JSON.stringify(String(MODE === "production")),
"process.env.TEST": JSON.stringify(String(TEST)),
"process.env.PROD": JSON.stringify(String(PROD)),
},
});
2 changes: 1 addition & 1 deletion vitest.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { defineConfig } from "vitest/config";
export default defineConfig({
test: {
globalSetup: ["./test/setup.global.ts"],
forceRerunTriggers: ["**/dist/index.mjs"],
forceRerunTriggers: ["**/src/**", "**/tsdown.config.ts"],
typecheck: { enabled: true },
setupFiles: ["./test/setup.ts"],
include: ["./test/**/*.test.ts"],
Expand Down
Loading