Skip to content

Commit

Permalink
add integration tests for addon creation flow
Browse files Browse the repository at this point in the history
  • Loading branch information
DavidWells committed Feb 21, 2019
1 parent 259dfbf commit 8c497f7
Show file tree
Hide file tree
Showing 7 changed files with 129 additions and 0 deletions.
63 changes: 63 additions & 0 deletions src/tests/addons.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
const path = require('path')
const test = require('ava')
const cliPath = require('./utils/cliPath')
const exec = require('./utils/exec')
const sitePath = path.join(__dirname, 'dummy-site')

const execOptions = {
stdio: [0, 1, 2],
cwd: sitePath,
env: {
...process.env,
NETLIFY_AUTH_TOKEN: process.env.NETLIFY_AUTH_TOKEN,
NETLIFY_SITE_ID: process.env.NETLIFY_SITE_ID
},
}

async function deleteAddon(name) {
const cliResponse = await exec(`${cliPath} addons:delete ${name}`, execOptions)
return cliResponse
}

// test.before(t => {
// // create site
// })

test.serial('netlify addon:list', async (t) => {
const regex = /^No addons currently installed/
const cliResponse = await exec(`${cliPath} addons:list`, execOptions)
t.is(regex.test(cliResponse.stdout), true)
})

test.serial('netlify addon:list --json', async (t) => {
const cliResponse = await exec(`${cliPath} addons:list --json`, execOptions)
const json = JSON.parse(cliResponse.stdout)
t.is(Array.isArray(json), true)
t.is(json.length, 0)
})

test.serial('netlify addon:create demo', async (t) => {
const regex = /Add-on "demo" created/
const cliResponse = await exec(`${cliPath} addons:create demo --TWILIO_ACCOUNT_SID lol`, execOptions)
t.is(regex.test(cliResponse.stdout), true)
})

test.serial('After creation netlify addon:list --json', async (t) => {
const cliResponse = await exec(`${cliPath} addons:list --json`, execOptions)
const json = JSON.parse(cliResponse.stdout)
t.is(Array.isArray(json), true)
t.is(json.length, 1)
t.is(json[0].service_slug, 'demo')
})

test.serial('netlify addon:delete demo', async (t) => {
const regex = /Add-on "demo" deleted/
const cliResponse = await deleteAddon('demo')
t.is(regex.test(cliResponse.stdout), true)
})

test.after('cleanup', async t => {
console.log('Performing cleanup')
// Run cleanup
await deleteAddon('demo')
})
16 changes: 16 additions & 0 deletions src/tests/dummy-site/build/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<!doctype html>
<html class="no-js" lang="">

<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title></title>
<meta name="description" content="">
<meta name="viewport" content="width=device-width, initial-scale=1">
</head>

<body>
<h1>⊂◉‿◉つ</h1>
</body>

</html>
16 changes: 16 additions & 0 deletions src/tests/dummy-site/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<!doctype html>
<html class="no-js" lang="">

<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title></title>
<meta name="description" content="">
<meta name="viewport" content="width=device-width, initial-scale=1">
</head>

<body>
<h1>⊂◉‿◉つ</h1>
</body>

</html>
3 changes: 3 additions & 0 deletions src/tests/dummy-site/netlify.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[build]
command = "npm run build"
publish = "build"
13 changes: 13 additions & 0 deletions src/tests/dummy-site/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"name": "dummy-site",
"version": "1.0.0",
"private": true,
"description": "",
"main": "index.js",
"scripts": {
"prebuild": "rm -rf build && mkdir build",
"build": "cp index.html build"
},
"author": "David Wells",
"license": "MIT"
}
5 changes: 5 additions & 0 deletions src/tests/utils/cliPath.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
const path = require('path')

const cliPath = path.join(__dirname, '..', '..', '..', 'bin/run')

module.exports = cliPath
13 changes: 13 additions & 0 deletions src/tests/utils/exec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
const { exec } = require('child_process')

module.exports = (cmd, opts) =>
new Promise((resolve, reject) => {
const dirOutput = (opts && opts.cwd) ? `\nDIR: ${opts.cwd}` : ''
console.log(`Running command...\nCMD: ${cmd}${dirOutput}`)
exec(cmd, opts, (err, stdout, stderr) => {
if (err) {
return reject(err)
}
return resolve({ stdout, stderr })
})
})

0 comments on commit 8c497f7

Please sign in to comment.