11import { parse } from "../../deps/semver.ts" ;
2- import { resolvesNext , stub } from "../../deps/std.ts" ;
2+ import { assertEquals , resolvesNext , stub } from "../../deps/std.ts" ;
33import { YAML } from "../../deps/yaml.ts" ;
44import { IContext } from "../context.ts" ;
55import { postVersionHook } from "./post.ts" ;
@@ -13,27 +13,73 @@ Deno.test("yml or yaml", async () => {
1313 regexp : async ( ) => await undefined ,
1414 } ,
1515 } ;
16- stub (
17- Deno ,
18- "stat" ,
19- resolvesNext < Deno . FileInfo > ( [
20- Object . assign ( new Deno . errors . NotFound ( "not found" ) ) , // version.yml, nah
21- {
22- isFile : true ,
23- } as Deno . FileInfo , // version.yaml, yah
24- ] ) ,
25- ) ;
26- stub (
27- Deno ,
28- "readTextFile" ,
29- resolvesNext ( [
30- "1.0.0" ,
31- YAML . stringify ( {
32- on : { post : [ { kind : "patch" , file : "test/example.csproj" } ] } ,
33- } ) ,
34- ] ) ,
35- ) ;
36- stub ( context . hooks , "patch" ) ;
37- stub ( context . hooks , "replace" ) ;
38- await postVersionHook ( context , parse ( "1.0.0" ) , parse ( "1.2.3" ) ) ;
16+ const stubs = [
17+ stub (
18+ Deno ,
19+ "stat" ,
20+ resolvesNext < Deno . FileInfo > ( [
21+ Object . assign ( new Deno . errors . NotFound ( "not found" ) ) , // version.yml, nah
22+ {
23+ isFile : true ,
24+ } as Deno . FileInfo , // version.yaml, yah
25+ ] ) ,
26+ ) ,
27+ stub (
28+ Deno ,
29+ "readTextFile" ,
30+ resolvesNext ( [
31+ "1.0.0" ,
32+ YAML . stringify ( {
33+ on : { post : [ { kind : "patch" , file : "test/example.csproj" } ] } ,
34+ } ) ,
35+ ] ) ,
36+ ) ,
37+ stub ( context . hooks , "patch" ) ,
38+ stub ( context . hooks , "replace" ) ,
39+ ] ;
40+ try {
41+ await postVersionHook ( context , parse ( "1.0.0" ) , parse ( "1.2.3" ) ) ;
42+ } finally {
43+ stubs . forEach ( ( s ) => s . restore ( ) ) ;
44+ }
45+ } ) ;
46+
47+ Deno . test ( "custom config" , async ( ) => {
48+ const context : IContext = {
49+ config : ".github/version-test.yml" ,
50+ githubDir : ".github" ,
51+ hooks : {
52+ patch : async ( ) => await undefined ,
53+ replace : async ( ) => await undefined ,
54+ regexp : async ( ) => await undefined ,
55+ } ,
56+ } ;
57+ let configPath : string | URL = "" ;
58+ const stubs = [
59+ stub (
60+ Deno ,
61+ "stat" ,
62+ resolvesNext < Deno . FileInfo > ( [
63+ { isFile : true } as Deno . FileInfo ,
64+ ] ) ,
65+ ) ,
66+ stub (
67+ Deno ,
68+ "readTextFile" ,
69+ async ( path , _opts ) => {
70+ configPath = path ;
71+ return await YAML . stringify ( {
72+ on : { post : [ ] } ,
73+ } ) ;
74+ } ,
75+ ) ,
76+ stub ( context . hooks , "patch" ) ,
77+ stub ( context . hooks , "replace" ) ,
78+ ] ;
79+ try {
80+ await postVersionHook ( context , parse ( "1.0.0" ) , parse ( "1.2.3" ) ) ;
81+ assertEquals ( configPath , ".github/version-test.yml" ) ;
82+ } finally {
83+ stubs . forEach ( ( s ) => s . restore ( ) ) ;
84+ }
3985} ) ;
0 commit comments