Skip to content

Commit f58e2bc

Browse files
committed
test: add tests
1 parent 1ce8837 commit f58e2bc

File tree

1 file changed

+77
-1
lines changed

1 file changed

+77
-1
lines changed

__tests__/devenv-e2e/013-configuration-file.spec.js

Lines changed: 77 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { describe, expect, it, jest } from '@jest/globals';
2-
import { mkdtemp, rm, mkdir, realpath } from 'node:fs/promises';
2+
import { mkdtemp, rm, mkdir, realpath, readFile, stat } from 'node:fs/promises';
33
import os from 'node:os';
44
import path from 'node:path';
55
import xdgBaseDir from 'xdg-basedir';
@@ -334,4 +334,80 @@ describe( 'vip dev-env configuration file', () => {
334334
cron: ! expectedCron,
335335
} );
336336
} );
337+
338+
it( 'should create .lando.local.yml if overrides have been provided', async () => {
339+
const slug = getProjectSlug();
340+
const expectedOverrides = `services:\n wordpress:\n services:\n pull_policy: never\n`;
341+
342+
expect( await checkEnvExists( slug ) ).toBe( false );
343+
344+
await writeConfigurationFile( tmpWorkingDirectoryPath, {
345+
'configuration-version': '1',
346+
slug,
347+
overrides: expectedOverrides,
348+
} );
349+
350+
const spawnOptions = {
351+
env,
352+
cwd: tmpWorkingDirectoryPath,
353+
};
354+
355+
const result = await cliTest.spawn(
356+
[ process.argv[ 0 ], vipDevEnvCreate ],
357+
spawnOptions,
358+
true
359+
);
360+
expect( result.rc ).toBe( 0 );
361+
expect( result.stdout ).toContain( `Using environment ${ slug }` );
362+
expect( result.stderr ).toBe( '' );
363+
364+
const data = readEnvironmentData( slug );
365+
expect( data ).toMatchObject( {
366+
siteSlug: slug,
367+
overrides: expectedOverrides,
368+
} );
369+
370+
const overrideFile = path.join( tmpPath, 'vip', 'dev-environment', slug, '.lando.local.yml' );
371+
const overrideContent = await readFile( overrideFile, 'utf8' );
372+
expect( overrideContent ).toBe( expectedOverrides );
373+
} );
374+
375+
it( 'should remove .lando.local.yml if no overrides have been provided', async () => {
376+
const slug = getProjectSlug();
377+
const overrides = ` |\n services:\n wordpress:\n services:\n pull_policy: never\n`;
378+
379+
expect( await checkEnvExists( slug ) ).toBe( false );
380+
381+
await writeConfigurationFile( tmpWorkingDirectoryPath, {
382+
'configuration-version': '1',
383+
slug,
384+
overrides,
385+
} );
386+
387+
const spawnOptions = {
388+
env,
389+
cwd: tmpWorkingDirectoryPath,
390+
};
391+
392+
let result = await cliTest.spawn( [ process.argv[ 0 ], vipDevEnvCreate ], spawnOptions, true );
393+
expect( result.rc ).toBe( 0 );
394+
expect( result.stdout ).toContain( `Using environment ${ slug }` );
395+
expect( result.stderr ).toBe( '' );
396+
397+
await writeConfigurationFile( tmpWorkingDirectoryPath, {
398+
'configuration-version': '1',
399+
slug,
400+
overrides,
401+
} );
402+
403+
result = await cliTest.spawn( [ process.argv[ 0 ], vipDevEnvUpdate ], spawnOptions, true );
404+
expect( result.rc ).toBe( 0 );
405+
expect( result.stderr ).toBe( '' );
406+
407+
const data = readEnvironmentData( slug );
408+
expect( data.overrides ).toBeFalsy();
409+
410+
const overrideFile = path.join( tmpPath, 'vip', 'dev-environment', slug, '.lando.local.yml' );
411+
return expect( stat( overrideFile ) ).rejects.toThrow();
412+
} );
337413
} );

0 commit comments

Comments
 (0)