1- import { createPlainLog , LogLevel , makeLog } from '../../spec-utils/log' ;
21import * as assert from 'assert' ;
2+ import * as os from 'os' ;
3+ import * as path from 'path' ;
4+ import { createPlainLog , LogLevel , makeLog } from '../../spec-utils/log' ;
35export const output = makeLog ( createPlainLog ( text => process . stdout . write ( text ) , ( ) => LogLevel . Trace ) ) ;
46import { fetchTemplate , SelectedTemplate } from '../../spec-configuration/containerTemplatesOCI' ;
5- import * as path from 'path' ;
67import { readLocalFile } from '../../spec-utils/pfs' ;
78
89describe ( 'fetchTemplate' , async function ( ) {
@@ -14,7 +15,8 @@ describe('fetchTemplate', async function () {
1415 const selectedTemplate : SelectedTemplate = {
1516 id : 'ghcr.io/devcontainers/templates/docker-from-docker:latest' ,
1617 options : { 'installZsh' : 'false' , 'upgradePackages' : 'true' , 'dockerVersion' : '20.10' , 'moby' : 'true' } ,
17- features : [ ]
18+ features : [ ] ,
19+ omitPaths : [ ] ,
1820 } ;
1921
2022 const dest = path . relative ( process . cwd ( ) , path . join ( __dirname , 'tmp1' ) ) ;
@@ -43,7 +45,8 @@ describe('fetchTemplate', async function () {
4345 const selectedTemplate : SelectedTemplate = {
4446 id : 'ghcr.io/devcontainers/templates/docker-from-docker:latest' ,
4547 options : { } ,
46- features : [ ]
48+ features : [ ] ,
49+ omitPaths : [ ] ,
4750 } ;
4851
4952 const dest = path . relative ( process . cwd ( ) , path . join ( __dirname , 'tmp2' ) ) ;
@@ -72,7 +75,8 @@ describe('fetchTemplate', async function () {
7275 const selectedTemplate : SelectedTemplate = {
7376 id : 'ghcr.io/devcontainers/templates/docker-from-docker:latest' ,
7477 options : { 'installZsh' : 'false' , 'upgradePackages' : 'true' , 'dockerVersion' : '20.10' , 'moby' : 'true' , 'enableNonRootDocker' : 'true' } ,
75- features : [ { id : 'ghcr.io/devcontainers/features/azure-cli:1' , options : { } } ]
78+ features : [ { id : 'ghcr.io/devcontainers/features/azure-cli:1' , options : { } } ] ,
79+ omitPaths : [ ] ,
7680 } ;
7781
7882 const dest = path . relative ( process . cwd ( ) , path . join ( __dirname , 'tmp3' ) ) ;
@@ -104,7 +108,8 @@ describe('fetchTemplate', async function () {
104108 const selectedTemplate : SelectedTemplate = {
105109 id : 'ghcr.io/devcontainers/templates/anaconda-postgres:latest' ,
106110 options : { 'nodeVersion' : 'lts/*' } ,
107- features : [ { id : 'ghcr.io/devcontainers/features/azure-cli:1' , options : { } } , { id : 'ghcr.io/devcontainers/features/git:1' , options : { 'version' : 'latest' , ppa : true } } ]
111+ features : [ { id : 'ghcr.io/devcontainers/features/azure-cli:1' , options : { } } , { id : 'ghcr.io/devcontainers/features/git:1' , options : { 'version' : 'latest' , ppa : true } } ] ,
112+ omitPaths : [ ] ,
108113 } ;
109114
110115 const dest = path . relative ( process . cwd ( ) , path . join ( __dirname , 'tmp4' ) ) ;
@@ -123,4 +128,109 @@ describe('fetchTemplate', async function () {
123128 assert . match ( devcontainer , / " g h c r .i o \/ d e v c o n t a i n e r s \/ f e a t u r e s \/ a z u r e - c l i : 1 " : { } / ) ;
124129 assert . match ( devcontainer , / " g h c r .i o \/ d e v c o n t a i n e r s \/ f e a t u r e s \/ g i t : 1 " : { \n \t \t \t " v e r s i o n " : " l a t e s t " , \n \t \t \t " p p a " : t r u e / ) ;
125130 } ) ;
126- } ) ;
131+
132+ describe ( 'omit-path' , async function ( ) {
133+ this . timeout ( '120s' ) ;
134+
135+ // https://github.com/codspace/templates/pkgs/container/templates%2Fmytemplate/255979159?tag=1.0.4
136+ const id = 'ghcr.io/codspace/templates/mytemplate@sha256:57cbf968907c74c106b7b2446063d114743ab3f63345f7c108c577915c535185' ;
137+ const templateFiles = [
138+ './c1.ts' ,
139+ './c2.ts' ,
140+ './c3.ts' ,
141+ './.devcontainer/devcontainer.json' ,
142+ './.github/dependabot.yml' ,
143+ './assets/hello.md' ,
144+ './assets/hi.md' ,
145+ './example-projects/exampleA/a1.ts' ,
146+ './example-projects/exampleA/.github/dependabot.yml' ,
147+ './example-projects/exampleA/subFolderA/a2.ts' ,
148+ './example-projects/exampleB/b1.ts' ,
149+ './example-projects/exampleB/.github/dependabot.yml' ,
150+ './example-projects/exampleB/subFolderB/b2.ts' ,
151+ ] ;
152+
153+ // NOTE: Certain files, like the 'devcontainer-template.json', are always filtered
154+ // out as they are not part of the Template.
155+ it ( 'Omit nothing' , async ( ) => {
156+ const selectedTemplate : SelectedTemplate = {
157+ id,
158+ options : { } ,
159+ features : [ ] ,
160+ omitPaths : [ ] ,
161+ } ;
162+
163+ const files = await fetchTemplate (
164+ { output, env : process . env } ,
165+ selectedTemplate ,
166+ path . join ( os . tmpdir ( ) , 'vsch-test-template-temp' , `${ Date . now ( ) } ` )
167+ ) ;
168+
169+ assert . ok ( files ) ;
170+ assert . strictEqual ( files . length , templateFiles . length ) ;
171+ for ( const file of templateFiles ) {
172+ assert . ok ( files . includes ( file ) ) ;
173+ }
174+ } ) ;
175+
176+ it ( 'Omit nested folder' , async ( ) => {
177+ const selectedTemplate : SelectedTemplate = {
178+ id,
179+ options : { } ,
180+ features : [ ] ,
181+ omitPaths : [ 'example-projects/exampleB/*' ] ,
182+ } ;
183+
184+ const files = await fetchTemplate (
185+ { output, env : process . env } ,
186+ selectedTemplate ,
187+ path . join ( os . tmpdir ( ) , 'vsch-test-template-temp' , `${ Date . now ( ) } ` )
188+ ) ;
189+
190+ const expectedRemovedFiles = [
191+ './example-projects/exampleB/b1.ts' ,
192+ './example-projects/example/.github/dependabot.yml' ,
193+ './example-projects/exampleB/subFolderB/b2.ts' ,
194+ ] ;
195+
196+ assert . ok ( files ) ;
197+ assert . strictEqual ( files . length , templateFiles . length - 3 ) ;
198+ for ( const file of expectedRemovedFiles ) {
199+ assert . ok ( ! files . includes ( file ) ) ;
200+ }
201+ } ) ;
202+
203+ it ( 'Omit single file, root folder, and nested folder' , async ( ) => {
204+ const selectedTemplate : SelectedTemplate = {
205+ id,
206+ options : { } ,
207+ features : [ ] ,
208+ omitPaths : [ '.github/*' , 'example-projects/exampleA/*' , 'c1.ts' ] ,
209+ } ;
210+
211+ const files = await fetchTemplate (
212+ { output, env : process . env } ,
213+ selectedTemplate ,
214+ path . join ( os . tmpdir ( ) , 'vsch-test-template-temp' , `${ Date . now ( ) } ` )
215+ ) ;
216+
217+ const expectedRemovedFiles = [
218+ './c1.ts' ,
219+ './.github/dependabot.yml' ,
220+ './example-projects/exampleA/a1.ts' ,
221+ './example-projects/exampleA/.github/dependabot.yml' ,
222+ './example-projects/exampleA/subFolderA/a2.ts' ,
223+ ] ;
224+
225+ assert . ok ( files ) ;
226+ assert . strictEqual ( files . length , templateFiles . length - 5 ) ;
227+ for ( const file of expectedRemovedFiles ) {
228+ assert . ok ( ! files . includes ( file ) ) ;
229+ }
230+ } ) ;
231+ } ) ;
232+
233+
234+ } ) ;
235+
236+
0 commit comments