11import { InternalOptions } from "../src/options-mapping" ;
2- import { addDeploy , setCommits } from "../src/sentry/releasePipeline" ;
2+ import {
3+ addDeploy ,
4+ cleanArtifacts ,
5+ createNewRelease ,
6+ finalizeRelease ,
7+ setCommits ,
8+ uploadSourceMaps ,
9+ } from "../src/sentry/releasePipeline" ;
310import { BuildContext } from "../src/types" ;
411
512const mockedAddSpanToTxn = jest . fn ( ) ;
@@ -11,9 +18,9 @@ jest.mock("../src/sentry/telemetry", () => {
1118 // eslint-disable-next-line @typescript-eslint/no-unsafe-return
1219 return {
1320 ...original ,
14- addSpanToTransaction : ( ) => {
21+ addSpanToTransaction : ( ctx : unknown , op : string ) => {
1522 // eslint-disable-next-line @typescript-eslint/no-unsafe-return
16- return mockedAddSpanToTxn ( ) ;
23+ return mockedAddSpanToTxn ( ctx , op ) ;
1724 } ,
1825 } ;
1926} ) ;
@@ -28,7 +35,11 @@ describe("Release Pipeline", () => {
2835
2936 const mockedCLI = {
3037 releases : {
38+ new : jest . fn ( ) ,
39+ execute : jest . fn ( ) ,
40+ uploadSourceMaps : jest . fn ( ) ,
3141 setCommits : jest . fn ( ) ,
42+ finalize : jest . fn ( ) ,
3243 newDeploy : jest . fn ( ) ,
3344 } ,
3445 } ;
@@ -38,13 +49,71 @@ describe("Release Pipeline", () => {
3849
3950 const ctx = { cli : mockedCLI , logger : mockedLogger } ;
4051
52+ beforeEach ( ( ) => {
53+ jest . clearAllMocks ( ) ;
54+ } ) ;
55+
56+ describe ( "createNewRelease" , ( ) => {
57+ it ( "makes a call to Sentry CLI's releases creation command" , async ( ) => {
58+ await createNewRelease (
59+ { release : "1.0.0" } as InternalOptions ,
60+ ctx as unknown as BuildContext
61+ ) ;
62+
63+ expect ( mockedCLI . releases . new ) . toHaveBeenCalledWith ( "1.0.0" ) ;
64+ expect ( mockedAddSpanToTxn ) . toHaveBeenCalledWith ( ctx , "function.plugin.create_release" ) ;
65+ expect ( mockedChildSpan . finish ) . toHaveBeenCalled ( ) ;
66+ } ) ;
67+ } ) ;
68+
69+ describe ( "cleanArtifacts" , ( ) => {
70+ it ( "doest do anything if cleanArtifacts is not true" , async ( ) => {
71+ await cleanArtifacts ( { } as InternalOptions , ctx as unknown as BuildContext ) ;
72+
73+ expect ( mockedCLI . releases . execute ) . not . toHaveBeenCalled ( ) ;
74+ expect ( mockedAddSpanToTxn ) . not . toHaveBeenCalled ( ) ;
75+ expect ( mockedChildSpan . finish ) . not . toHaveBeenCalled ( ) ;
76+ } ) ;
77+
78+ it ( "makes a call to Sentry CLI's artifact removal command if `cleanArtifacts` is set" , async ( ) => {
79+ await cleanArtifacts (
80+ { release : "1.0.0" , cleanArtifacts : true } as InternalOptions ,
81+ ctx as unknown as BuildContext
82+ ) ;
83+
84+ expect ( mockedCLI . releases . execute ) . toHaveBeenCalledWith (
85+ [ "releases" , "files" , "1.0.0" , "delete" , "--all" ] ,
86+ true
87+ ) ;
88+ expect ( mockedAddSpanToTxn ) . toHaveBeenCalledWith ( ctx , "function.plugin.clean_artifacts" ) ;
89+ expect ( mockedChildSpan . finish ) . toHaveBeenCalled ( ) ;
90+ } ) ;
91+ } ) ;
92+
93+ describe ( "uploadSourceMaps" , ( ) => {
94+ it ( "makes a call to Sentry CLI's sourcemaps upload command" , async ( ) => {
95+ const options = {
96+ release : "1.0.0" ,
97+ include : [ { paths : [ "dist" ] } ] ,
98+ } as InternalOptions ;
99+
100+ await uploadSourceMaps ( options , ctx as unknown as BuildContext ) ;
101+
102+ expect ( mockedCLI . releases . uploadSourceMaps ) . toHaveBeenCalledWith ( "1.0.0" , {
103+ include : [ { paths : [ "dist" ] } ] ,
104+ } ) ;
105+ expect ( mockedAddSpanToTxn ) . toHaveBeenCalledWith ( ctx , "function.plugin.upload_sourcemaps" ) ;
106+ expect ( mockedChildSpan . finish ) . toHaveBeenCalled ( ) ;
107+ } ) ;
108+ } ) ;
109+
41110 describe ( "setCommits" , ( ) => {
42111 it ( "doesn't do anything if `setCommits` option is not specified" , async ( ) => {
43112 await setCommits ( { } as InternalOptions , ctx as unknown as BuildContext ) ;
44113
45114 expect ( mockedCLI . releases . setCommits ) . not . toHaveBeenCalled ( ) ;
46- expect ( mockedAddSpanToTxn ) . toHaveBeenCalled ( ) ;
47- expect ( mockedChildSpan . finish ) . toHaveBeenCalled ( ) ;
115+ expect ( mockedAddSpanToTxn ) . not . toHaveBeenCalled ( ) ;
116+ expect ( mockedChildSpan . finish ) . not . toHaveBeenCalled ( ) ;
48117 } ) ;
49118
50119 it ( "makes a call to Sentry CLI if the correct options are specified" , async ( ) => {
@@ -54,7 +123,28 @@ describe("Release Pipeline", () => {
54123 ) ;
55124
56125 expect ( mockedCLI . releases . setCommits ) . toHaveBeenCalledWith ( "1.0.0" , { auto : true } ) ;
57- expect ( mockedAddSpanToTxn ) . toHaveBeenCalled ( ) ;
126+ expect ( mockedAddSpanToTxn ) . toHaveBeenCalledWith ( ctx , "function.plugin.set_commits" ) ;
127+ expect ( mockedChildSpan . finish ) . toHaveBeenCalled ( ) ;
128+ } ) ;
129+ } ) ;
130+
131+ describe ( "finalizeRelease" , ( ) => {
132+ it ( "doesn't do anything if `finalize` is not set" , async ( ) => {
133+ await finalizeRelease ( { } as InternalOptions , ctx as unknown as BuildContext ) ;
134+
135+ expect ( mockedCLI . releases . finalize ) . not . toHaveBeenCalled ( ) ;
136+ expect ( mockedAddSpanToTxn ) . not . toHaveBeenCalled ( ) ;
137+ expect ( mockedChildSpan . finish ) . not . toHaveBeenCalled ( ) ;
138+ } ) ;
139+
140+ it ( "makes a call to Sentry CLI's release finalization command if `finalize` is true" , async ( ) => {
141+ await finalizeRelease (
142+ { release : "1.0.0" , finalize : true } as InternalOptions ,
143+ ctx as unknown as BuildContext
144+ ) ;
145+
146+ expect ( mockedCLI . releases . finalize ) . toHaveBeenCalledWith ( "1.0.0" ) ;
147+ expect ( mockedAddSpanToTxn ) . toHaveBeenCalledWith ( ctx , "function.plugin.finalize_release" ) ;
58148 expect ( mockedChildSpan . finish ) . toHaveBeenCalled ( ) ;
59149 } ) ;
60150 } ) ;
@@ -64,8 +154,8 @@ describe("Release Pipeline", () => {
64154 await addDeploy ( { } as InternalOptions , ctx as unknown as BuildContext ) ;
65155
66156 expect ( mockedCLI . releases . newDeploy ) . not . toHaveBeenCalled ( ) ;
67- expect ( mockedAddSpanToTxn ) . toHaveBeenCalled ( ) ;
68- expect ( mockedChildSpan . finish ) . toHaveBeenCalled ( ) ;
157+ expect ( mockedAddSpanToTxn ) . not . toHaveBeenCalled ( ) ;
158+ expect ( mockedChildSpan . finish ) . not . toHaveBeenCalled ( ) ;
69159 } ) ;
70160
71161 it ( "makes a call to Sentry CLI if the correct options are specified" , async ( ) => {
0 commit comments