11/*---------------------------------------------------------------------------------------------
22 * web/lib/extensions.mjs — run: node web/test/unit/extensions.test.js
33 *
4- * Which of Code-OSS's extensions the browser edition carries, how they are staged, and what the build id is made
5- * of for them. The id must see exactly what is staged: a grammar that changed and an id that did not is a stale
4+ * Which of Code-OSS's extensions the browser edition carries, how they are staged, and that the build id changes
5+ * with them. The id must see exactly what is staged: a grammar that changed and an id that did not is a stale
66 * file for a year under an immutable prefix.
77 *--------------------------------------------------------------------------------------------*/
88// @ts -check
@@ -21,7 +21,7 @@ const write = (root, rel, text) => { const f = path.join(root, rel); fs.mkdirSyn
2121
2222( async ( ) => {
2323 const lib = path . join ( __dirname , '..' , '..' , 'lib' ) ;
24- const { declarativeExtensionNames, stageDeclarativeExtensions, copyExtension , COPY_SKIP } = await import ( pathToFileURL ( path . join ( lib , 'extensions.mjs' ) ) . href ) ;
24+ const { declarativeExtensionNames, stageDeclarativeExtensions } = await import ( pathToFileURL ( path . join ( lib , 'extensions.mjs' ) ) . href ) ;
2525 const { hashTree } = await import ( pathToFileURL ( path . join ( lib , 'fingerprint.mjs' ) ) . href ) ;
2626
2727 const checkout = ( ) => {
@@ -63,11 +63,14 @@ const write = (root, rel, text) => { const f = path.join(root, rel); fs.mkdirSyn
6363 } ) ;
6464
6565 await test ( 'the build id sees a changed grammar, a new extension and a removed one — and not a test file' , ( ) => {
66+ // scripts/build-web.mjs names the build after a hash of its staging folder; this stages and hashes the same way.
6667 const d = checkout ( ) ;
6768 const id = ( ) => {
68- const h = createHash ( 'sha256' ) ;
69- for ( const name of declarativeExtensionNames ( d , [ 'baked' ] ) ) { h . update ( '\0ext\0' + name ) ; hashTree ( h , path . join ( d , name ) , { skip : [ ...COPY_SKIP , '.DS_Store' ] } ) ; }
70- return h . digest ( 'hex' ) ;
69+ const out = fs . mkdtempSync ( path . join ( os . tmpdir ( ) , 'lc-ext-out-' ) ) ;
70+ try {
71+ stageDeclarativeExtensions ( d , out , { exclude : [ 'baked' ] } ) ;
72+ return hashTree ( createHash ( 'sha256' ) , out , { skip : [ '.DS_Store' ] } ) . digest ( 'hex' ) ;
73+ } finally { fs . rmSync ( out , { recursive : true , force : true } ) ; }
7174 } ;
7275 try {
7376 const base = id ( ) ;
@@ -80,19 +83,9 @@ const write = (root, rel, text) => { const f = path.join(root, rel); fs.mkdirSyn
8083 fs . rmSync ( path . join ( d , 'extra' ) , { recursive : true } ) ;
8184 assert . strictEqual ( id ( ) , changed , 'and back' ) ;
8285 write ( d , 'json/test/fixture.json' , '{"more":1}' ) ;
83- assert . strictEqual ( id ( ) , changed , 'a test file is not staged, so it is not part of the build' ) ;
84- } finally { fs . rmSync ( d , { recursive : true , force : true } ) ; }
85- } ) ;
86-
87- await test ( 'what the id skips is what the copy skips' , ( ) => {
88- for ( const name of [ 'node_modules' , 'test' , 'src' , '.git' ] ) { assert . ok ( COPY_SKIP . includes ( name ) , name ) ; }
89- const d = checkout ( ) ;
90- const out = fs . mkdtempSync ( path . join ( os . tmpdir ( ) , 'lc-ext-out-' ) ) ;
91- try {
9286 write ( d , 'json/node_modules/x/index.js' , 'x' ) ;
93- copyExtension ( path . join ( d , 'json' ) , path . join ( out , 'json' ) ) ;
94- assert . ok ( ! fs . existsSync ( path . join ( out , 'json' , 'node_modules' ) ) ) ;
95- } finally { fs . rmSync ( d , { recursive : true , force : true } ) ; fs . rmSync ( out , { recursive : true , force : true } ) ; }
87+ assert . strictEqual ( id ( ) , changed , 'a test file or a dependency is not staged, so it is not part of the build' ) ;
88+ } finally { fs . rmSync ( d , { recursive : true , force : true } ) ; }
9689 } ) ;
9790
9891 console . log ( `\n${ n } tests passed` ) ;
0 commit comments