Skip to content
This repository was archived by the owner on Oct 20, 2022. It is now read-only.

Commit 335a0f6

Browse files
committed
Add test for netlify.toml
1 parent 2487c1a commit 335a0f6

File tree

2 files changed

+56
-0
lines changed

2 files changed

+56
-0
lines changed

netlify-config-parser.test.js

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
const path = require('path')
2+
3+
const test = require('ava')
4+
const parser = require('./netlify-config-parser')
5+
6+
const testFilesDir = path.resolve('__dirname', '../', 'test-files')
7+
8+
test('netlify.toml redirects parsing', async t => {
9+
const result = await parser.parse(path.resolve(testFilesDir, 'netlify.toml'))
10+
t.deepEqual(
11+
[
12+
{
13+
path: '/old-path',
14+
to: '/new-path',
15+
status: 301,
16+
conditions: {
17+
Country: ['US'],
18+
Language: ['en'],
19+
Role: ['admin'],
20+
},
21+
force: false,
22+
params: {
23+
path: ':path',
24+
},
25+
},
26+
{
27+
path: '/search',
28+
to: 'https://api.mysearch.com',
29+
status: 200,
30+
force: true,
31+
signed: 'API_SIGNATURE_TOKEN',
32+
proxy: true,
33+
headers: {
34+
'X-From': 'Netlify',
35+
},
36+
},
37+
],
38+
result.success
39+
)
40+
})

test-files/netlify.toml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
[[redirects]]
2+
from = "/old-path"
3+
to = "/new-path"
4+
status = 301
5+
force = false
6+
query = {path = ":path"}
7+
conditions = {Language = ["en"], Country = ["US"], Role = ["admin"]}
8+
9+
## This rule redirects to an external API, signing requests with a secret
10+
[[redirects]]
11+
from = "/search"
12+
to = "https://api.mysearch.com"
13+
status = 200
14+
force = true # COMMENT: ensure that we always redirect
15+
headers = {X-From = "Netlify"}
16+
signed = "API_SIGNATURE_TOKEN"

0 commit comments

Comments
 (0)