11import path from "node:path" ;
2+ import * as core from "@actions/core" ;
23import type { Changeset } from "@changesets/types" ;
34import { writeChangeset } from "@changesets/write" ;
45import { createFixture } from "fs-fixture" ;
5- import { beforeEach , describe , expect , it , vi } from "vitest" ;
6+ import { afterEach , beforeEach , describe , expect , it , vi } from "vitest" ;
67import { GitHub } from "./github.ts" ;
7- import { runVersion } from "./run.ts" ;
8+ import { runPublish , runVersion } from "./run.ts" ;
89
910vi . mock ( "@actions/github" , ( ) => ( {
1011 context : {
@@ -20,6 +21,10 @@ vi.mock("@actions/github", () => ({
2021 graphql : mockedGraphql ,
2122 } ) ,
2223} ) ) ;
24+ vi . mock ( "@actions/core" , async ( importOriginal ) => ( {
25+ ...( await importOriginal < typeof import ( "@actions/core" ) > ( ) ) ,
26+ warning : vi . fn ( ) ,
27+ } ) ) ;
2328vi . mock ( "@changesets/ghcommit" ) ;
2429
2530let mockedGithubMethods = {
@@ -102,6 +107,59 @@ beforeEach(() => {
102107 vi . clearAllMocks ( ) ;
103108} ) ;
104109
110+ afterEach ( ( ) => {
111+ vi . unstubAllEnvs ( ) ;
112+ } ) ;
113+
114+ describe ( "publish" , ( ) => {
115+ it ( "warns when a custom publish script does not create the output file" , async ( ) => {
116+ await using fixture = await createSimpleProjectFixture ( ) ;
117+ const cwd = fixture . path ;
118+ vi . stubEnv ( "RUNNER_TEMP" , cwd ) ;
119+
120+ const result = await runPublish ( {
121+ script : 'node -e "void 0"' ,
122+ github : createGithub ( cwd ) ,
123+ createGithubReleases : true ,
124+ pushGitTags : true ,
125+ cwd,
126+ } ) ;
127+
128+ expect ( result ) . toEqual ( { published : false , exitCode : 0 } ) ;
129+ expect ( core . warning ) . toHaveBeenCalledWith (
130+ expect . stringContaining (
131+ "GitHub releases and git tags cannot be created without this output" ,
132+ ) ,
133+ ) ;
134+ } ) ;
135+
136+ it ( "throws when the built-in publish command does not create the output file" , async ( ) => {
137+ await using fixture = await createFixture ( {
138+ "node_modules/@changesets/cli/package.json" : JSON . stringify ( {
139+ name : "@changesets/cli" ,
140+ type : "module" ,
141+ } ) ,
142+ "node_modules/@changesets/cli/bin.js" : "" ,
143+ "package.json" : JSON . stringify ( {
144+ name : "simple-project" ,
145+ version : "1.0.0" ,
146+ } ) ,
147+ "package-lock.json" : "" ,
148+ } ) ;
149+ const cwd = fixture . path ;
150+ vi . stubEnv ( "RUNNER_TEMP" , cwd ) ;
151+
152+ await expect (
153+ runPublish ( {
154+ github : createGithub ( cwd ) ,
155+ createGithubReleases : true ,
156+ pushGitTags : true ,
157+ cwd,
158+ } ) ,
159+ ) . rejects . toThrow ( "Failed to read changesets output at" ) ;
160+ } ) ;
161+ } ) ;
162+
105163describe ( "version" , ( ) => {
106164 it ( "creates simple PR" , async ( ) => {
107165 await using fixture = await createSimpleProjectFixture ( ) ;
0 commit comments