@@ -4,7 +4,7 @@ import type { DirectoryResult } from "tmp-promise";
44import { dir } from "tmp-promise" ;
55import { join } from "path" ;
66import { createLockFileForStandardQuery } from "../../../../src/local-queries/standard-queries" ;
7- import { outputFile , pathExists } from "fs-extra" ;
7+ import { outputFile , pathExists , readFile } from "fs-extra" ;
88
99describe ( "createLockFileForStandardQuery" , ( ) => {
1010 let tmpDir : DirectoryResult ;
@@ -41,37 +41,34 @@ describe("createLockFileForStandardQuery", () => {
4141 } ) ;
4242
4343 describe ( "when the lock file exists" , ( ) => {
44- let lockfilePath : string ;
45-
46- beforeEach ( async ( ) => {
47- lockfilePath = join ( packPath , "qlpack.lock.yml" ) ;
48-
49- packPacklist . mockResolvedValue ( [ qlpackPath , lockfilePath , queryPath ] ) ;
50- } ) ;
51-
52- it ( "does not resolve or install dependencies" , async ( ) => {
53- expect ( await createLockFileForStandardQuery ( mockCli , queryPath ) ) . toEqual ( {
54- cleanup : undefined ,
55- } ) ;
56-
57- expect ( packResolveDependencies ) . not . toHaveBeenCalled ( ) ;
58- expect ( clearCache ) . not . toHaveBeenCalled ( ) ;
59- expect ( packInstall ) . not . toHaveBeenCalled ( ) ;
60- } ) ;
61-
62- it ( "does not resolve or install dependencies with a codeql-pack.lock.yml" , async ( ) => {
63- lockfilePath = join ( packPath , "codeql-pack.lock.yml" ) ;
64-
65- packPacklist . mockResolvedValue ( [ qlpackPath , lockfilePath , queryPath ] ) ;
66-
67- expect ( await createLockFileForStandardQuery ( mockCli , queryPath ) ) . toEqual ( {
68- cleanup : undefined ,
69- } ) ;
70-
71- expect ( packResolveDependencies ) . not . toHaveBeenCalled ( ) ;
72- expect ( clearCache ) . not . toHaveBeenCalled ( ) ;
73- expect ( packInstall ) . not . toHaveBeenCalled ( ) ;
74- } ) ;
44+ it . each ( [ "qlpack.lock.yml" , "codeql-pack.lock.yml" ] ) (
45+ "does not resolve or install dependencies with %s" ,
46+ async ( lockFileName ) => {
47+ const lockFilePath = join ( packPath , lockFileName ) ;
48+ const lockFileContents = `${ lockFileName } contents` ;
49+ await outputFile ( lockFilePath , lockFileContents ) ;
50+
51+ const { cleanup } = await createLockFileForStandardQuery (
52+ mockCli ,
53+ queryPath ,
54+ ) ;
55+
56+ expect ( {
57+ cleanup,
58+ packResolveDependenciesCallCount :
59+ packResolveDependencies . mock . calls . length ,
60+ clearCacheCallCount : clearCache . mock . calls . length ,
61+ packInstallCallCount : packInstall . mock . calls . length ,
62+ lockFileContents : await readFile ( lockFilePath , "utf8" ) ,
63+ } ) . toEqual ( {
64+ cleanup : undefined ,
65+ packResolveDependenciesCallCount : 0 ,
66+ clearCacheCallCount : 0 ,
67+ packInstallCallCount : 0 ,
68+ lockFileContents,
69+ } ) ;
70+ } ,
71+ ) ;
7572 } ) ;
7673
7774 describe ( "when the lock file does not exist" , ( ) => {
0 commit comments