-
Notifications
You must be signed in to change notification settings - Fork 53
/
tests.js
93 lines (82 loc) · 3.19 KB
/
tests.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
import { promises as fs } from 'fs'
import { platform } from 'process'
import { Fixture } from '@netlify/testing'
import test from 'ava'
import tmp from 'tmp-promise'
test('Does not mutate read-only properties', async (t) => {
const { netlifyConfig } = await new Fixture('./fixtures/readonly_properties')
.withFlags({
featureFlags: { netlify_build_deploy_configuration_api: true },
})
.runWithBuildAndIntrospect()
t.deepEqual(netlifyConfig.plugins, [])
})
test('Loads configuration data that has been generated by the build command', async (t) => {
const expectedImageDomains = [
'domain1.from-toml.netlify',
'domain2.from-toml.netlify',
'domain1.from-api.netlify',
'domain2.from-api.netlify',
]
const systemLogFile = await tmp.file()
const { netlifyConfig } = await new Fixture('./fixtures/from_build_command')
.withFlags({
debug: false,
featureFlags: { netlify_build_deploy_configuration_api: true },
systemLogFile: systemLogFile.fd,
})
.runWithBuildAndIntrospect()
t.deepEqual(netlifyConfig.images, {
remote_images: expectedImageDomains,
})
if (platform !== 'win32') {
const systemLog = await fs.readFile(systemLogFile.path, { encoding: 'utf8' })
const match = systemLog.match(/Netlify configuration property "images.remote_images" value changed to \[(.*)\]/s)
const imageDomains = JSON.parse(`[${match[1].replace(/'/g, '"')}]`)
t.deepEqual(imageDomains, expectedImageDomains)
}
})
test('In a monorepo setup, loads package-specific configuration data', async (t) => {
const fixture = await new Fixture('./fixtures/monorepo').withCopyRoot({ git: false })
const { success, netlifyConfig } = await fixture
.withFlags({
cwd: fixture.repositoryRoot,
featureFlags: { netlify_build_deploy_configuration_api: true },
packagePath: 'apps/app-1',
})
.runBuildProgrammatic()
t.true(success)
t.deepEqual(netlifyConfig.images, {
remote_images: ['domain1.netlify', 'domain2.netlify'],
})
})
test('Configuration data is exposed to build plugins in the `onBuild` event', async (t) => {
const { netlifyConfig, success } = await new Fixture('./fixtures/with_build_plugin')
.withFlags({
featureFlags: { netlify_build_deploy_configuration_api: true },
})
.runWithBuildAndIntrospect()
t.deepEqual(netlifyConfig.images, {
remote_images: ['domain1.from-api.netlify', 'domain2.from-api.netlify', 'domain1.from-plugin.netlify'],
})
t.true(success)
})
test('Throws an error if the deploy configuration file is malformed', async (t) => {
const { output, success } = await new Fixture('./fixtures/malformed_config')
.withFlags({
featureFlags: { netlify_build_deploy_configuration_api: true },
})
.runWithBuildAndIntrospect()
t.false(success)
t.true(
output.includes(`Error: An error occured while processing the platform configurarion defined by your framework`),
)
})
test('Does not throw an error if the deploy configuration file is missing', async (t) => {
const { success } = await new Fixture('./fixtures/missing_config')
.withFlags({
featureFlags: { netlify_build_deploy_configuration_api: true },
})
.runWithBuildAndIntrospect()
t.true(success)
})