-
Notifications
You must be signed in to change notification settings - Fork 340
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(tests): create test site builder and refactor dev command tests
- Loading branch information
Showing
36 changed files
with
1,942 additions
and
1,181 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,52 @@ | ||
const test = require('ava') | ||
const path = require('path') | ||
const { getEnvSettings } = require('./env') | ||
const { withSiteBuilder } = require('../../tests/utils/siteBuilder') | ||
|
||
const contextSite = path.join(__dirname, '..', '..', 'tests', 'context-site') | ||
const dummySite = path.join(__dirname, '..', '..', 'tests', 'dummy-site') | ||
const craSite = path.join(__dirname, '..', '..', 'tests', 'site-cra') | ||
test('should return empty object for a site with no .env file', async t => { | ||
await withSiteBuilder('site-without-env-file', async builder => { | ||
await builder.buildAsync() | ||
|
||
test('no .env files', async t => { | ||
const vars = await getEnvSettings(contextSite) | ||
t.deepEqual(vars, {}) | ||
const vars = await getEnvSettings(builder.directory) | ||
t.deepEqual(vars, {}) | ||
}) | ||
}) | ||
|
||
test('.env.development file', async t => { | ||
const vars = await getEnvSettings(dummySite) | ||
t.deepEqual(vars, { | ||
file: path.resolve(dummySite, '.env.development'), | ||
vars: { | ||
EASY_VAR: 'true', | ||
DUMMY_VAR: 'false', | ||
}, | ||
test('should read env vars from .env.development file', async t => { | ||
await withSiteBuilder('site-with-envs-file', async builder => { | ||
builder | ||
.withEnvFile({ | ||
path: '.env', | ||
env: { TEST: 'FROM_ENV' }, | ||
}) | ||
.withEnvFile({ | ||
path: '.env.development', | ||
env: { TEST: 'FROM_DEVELOPMENT_ENV' }, | ||
}) | ||
await builder.buildAsync() | ||
|
||
const vars = await getEnvSettings(builder.directory) | ||
t.deepEqual(vars, { | ||
file: path.resolve(builder.directory, '.env.development'), | ||
vars: { | ||
TEST: 'FROM_DEVELOPMENT_ENV', | ||
}, | ||
}) | ||
}) | ||
}) | ||
|
||
test('.env file', async t => { | ||
const vars = await getEnvSettings(craSite) | ||
t.deepEqual(vars, { | ||
file: path.resolve(craSite, '.env'), | ||
vars: {}, | ||
test('should handle empty .env file', async t => { | ||
await withSiteBuilder('site-with-empty-env-file', async builder => { | ||
builder.withEnvFile({ | ||
path: '.env', | ||
}) | ||
|
||
await builder.buildAsync() | ||
|
||
const vars = await getEnvSettings(builder.directory) | ||
t.deepEqual(vars, { | ||
file: path.resolve(builder.directory, '.env'), | ||
vars: {}, | ||
}) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,38 @@ | ||
const test = require('ava') | ||
const path = require('path') | ||
const { withSiteBuilder } = require('../../tests/utils/siteBuilder') | ||
const { getFunctions } = require('./get-functions.js') | ||
const { findModuleDir } = require('./finders') | ||
const sitePath = path.join(__dirname, '..', '..', 'tests', 'dummy-site') | ||
|
||
test('pass empty string', t => { | ||
test('should return empty object when an empty string is provided', t => { | ||
const f = getFunctions('') | ||
t.deepEqual(f, {}) | ||
}) | ||
|
||
test('pass directory with no *.js files', t => { | ||
const f = getFunctions(sitePath) | ||
t.deepEqual(f, {}) | ||
test('should return an empty object for a directory with no js files', async t => { | ||
await withSiteBuilder('site-without-functions', async builder => { | ||
await builder.buildAsync() | ||
|
||
const f = getFunctions(builder.directory) | ||
t.deepEqual(f, {}) | ||
}) | ||
}) | ||
|
||
test('pass dummy repository with *.js files', t => { | ||
const sitePath = path.join(__dirname, '..', '..', 'tests', 'dummy-repo') | ||
const f = getFunctions(sitePath) | ||
t.deepEqual(f, { | ||
index: { | ||
functionPath: path.join(sitePath, 'index.js'), | ||
moduleDir: findModuleDir(sitePath), | ||
}, | ||
test('should return object with function details for a directory with js files', async t => { | ||
await withSiteBuilder('site-without-functions', async builder => { | ||
builder.withFunction({ | ||
path: 'index.js', | ||
handler: '', | ||
}) | ||
await builder.buildAsync() | ||
|
||
const functions = path.join(builder.directory, 'functions') | ||
const f = getFunctions(functions) | ||
t.deepEqual(f, { | ||
index: { | ||
functionPath: path.join(functions, 'index.js'), | ||
moduleDir: findModuleDir(functions), | ||
}, | ||
}) | ||
}) | ||
}) |
Oops, something went wrong.