Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ARA-818 jest tests #1840

Merged
merged 12 commits into from
Mar 29, 2021
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,7 @@ packages/cli/src/knownRoles.json

npm-shrinkwrap.json
package-lock.json

packages/*/test/__snapshots__/
packages/*/test/*/__snapshots__/
packages/*/test/*/*/__snapshots__/
24 changes: 24 additions & 0 deletions packages/cli/jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/*
* For a detailed explanation regarding each configuration property, visit:
* https://jestjs.io/docs/en/configuration.html
*/

module.exports = {
// The directory where Jest should output its coverage files
coverageDirectory: 'coverage',

// Indicates which provider should be used to instrument code for coverage
coverageProvider: 'babel',

// The test environment that will be used for testing
testEnvironment: 'node',

// Jest Runner
runner: 'jest-serial-runner',

// Global Teardown Config
globalTeardown: '../../scripts/teardown-logic.js',

// Verbose mode
verbose: true,
}
26 changes: 9 additions & 17 deletions packages/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@
"lint": "eslint src test",
"lint:fix": "yarn lint -- --fix",
"prepublishOnly": "synp --source-file yarn.lock && npm shrinkwrap",
"test": "ava --verbose --timeout=10m",
"test:watch": "ava --watch --timeout=10m",
"test": "jest ./test --runInBand --forceExit",
"test:watch": "jest ./test --watch",
"test:clean": "rm -rf ./.tmp && yarn test:reset-cache",
"test:reset-cache": "ava --reset-cache --timeout=10m",
"test:update-snapshots": "yarn test:clean && yarn test -- --update-snapshots",
"test:reset-cache": "jest ./test --clearCache",
"test:update-snapshots": "yarn test --updateSnapshot",
"test:coverage:html": "nyc --all --reporter html yarn test",
"test:coverage": "nyc --all --reporter text --reporter text-summary --reporter lcovonly yarn test"
"test:coverage": "nyc --all --reporter text --reporter text-summary --reporter lcovonly yarn test:update-snapshots"
},
"files": [
"aliases",
Expand Down Expand Up @@ -110,19 +110,19 @@
"@babel/plugin-proposal-optional-chaining": "^7.8.3",
"@babel/preset-env": "^7.1.0",
"@babel/register": "^7.0.0",
"ava": "^3.8.2",
"babel-eslint": "^10.0.1",
"babel-plugin-istanbul": "^6.0.0",
"core-js": "^3.1.4",
"eslint": "^7.4.0",
"eslint-config-prettier": "^6.11.0",
"eslint-config-standard": "^14.1.0",
"eslint-plugin-ava": "^10.0.0",
"eslint-plugin-import": "^2.14.0",
"eslint-plugin-node": "^11.1.0",
"eslint-plugin-prettier": "^3.0.0",
"eslint-plugin-promise": "^4.0.1",
"eslint-plugin-standard": "^4.0.0",
"jest": "^26.6.3",
"jest-serial-runner": "^1.1.0",
"nyc": "^15.0.1",
"prettier": "^2.0.4",
"proxyquire": "^2.1.0",
Expand All @@ -141,14 +141,6 @@
"defaultGasPrice": "2",
"defaultIpfsTimeout": "300000"
},
"ava": {
"require": [
"@babel/register"
],
"files": [
"test/**/*.test.js"
]
},
"nyc": {
"include": [
"src/**/*.js",
Expand Down Expand Up @@ -187,11 +179,11 @@
],
"env": {
"es6": true,
"node": true
"node": true,
"jest": true
},
"extends": [
"standard",
"plugin:ava/recommended",
"plugin:prettier/recommended"
],
"parser": "babel-eslint"
Expand Down
6 changes: 2 additions & 4 deletions packages/cli/test/apm/apm-versions.test.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import test from 'ava'
//
import parseCli from '../parseCli'

test('fetches app versions', async (t) => {
test('fetches app versions', async () => {
const output = await parseCli(['apm', 'versions', 'voting', '--debug'])

t.assert(output.includes('voting.aragonpm.eth'))
expect(output.includes('voting.aragonpm.eth')).toBe(true)
})
122 changes: 65 additions & 57 deletions packages/cli/test/app/app.test.js
Original file line number Diff line number Diff line change
@@ -1,99 +1,107 @@
import test from 'ava'
import parseCli from '../parseCli'

test.serial('fetches app versions', async (t) => {
jest.setTimeout(60000)

test('fetches app versions', async () => {
const output = await parseCli(['apm', 'versions', 'voting', '--debug'])

t.assert(output.includes('voting.aragonpm.eth'))
expect(output.includes('voting.aragonpm.eth')).toBe(true)
})

test.serial('fetches app versions with full ens name', async (t) => {
test('fetches app versions with full ens name', async () => {
const output = await parseCli([
'apm',
'versions',
'finance.aragonpm.eth',
'--debug',
])

t.assert(output.includes('finance.aragonpm.eth'))
expect(output.includes('finance.aragonpm.eth')).toBe(true)
})

test.serial(
'publish fails if not in an aragon project directory',
async (t) => {
await t.throwsAsync(() => {
return parseCli([
'apm',
'publish',
'major',
'--files',
'app',
'--skip-confirmation',
'--no-propagate-content',
'--debug',
])
})
}
)
test('publish fails if not in an aragon project directory', async () => {
try {
await parseCli([
'apm',
'publish',
'major',
'--files',
'app',
'--skip-confirmation',
'--no-propagate-content',
'--debug',
])
// eslint-disable-next-line no-undef
fail('it should not reach here')
} catch (error) {}
})

test.serial('grant fails if not in an aragon project directory', async (t) => {
await t.throwsAsync(async () => {
return parseCli([
test('grant fails if not in an aragon project directory', async () => {
try {
await parseCli([
'apm',
'grant',
'0x8401Eb5ff34cc943f096A32EF3d5113FEbE8D4Eb',
'--debug',
])
})
// eslint-disable-next-line no-undef
fail('it should not reach here')
} catch (error) {}
})

test.serial('fetches app info', async (t) => {
test('fetches app info', async () => {
const output = await parseCli(['apm', 'info', 'finance', '--debug'])

t.assert(
output.includes('"name": "Finance"'),
expect(output.includes('"name": "Finance"')).toEqual(
true,
"App info doesn't contain name"
)
t.assert(
output.includes('"author": "Aragon Association",'),
expect(output.includes('"author": "Aragon Association",')).toEqual(
true,
"App info doesn't contain author"
)
t.assert(
expect(
output.includes(
'"description": "Manage an organization\'s financial assets"'
),
"App info doesn't contain description"
)
t.assert(
)
).toEqual(true, "App info doesn't contain description")
expect(
output.includes(
'"changelog_url": "https://github.com/aragon/aragon-apps/releases"'
),
"App info doesn't contain changelog url"
)
t.assert(
)
).toEqual(true, "App info doesn't contain changelog url")
expect(
output.includes(
'"source_url": "https://github.com/aragon/aragon-apps/blob/master/apps/finance"'
),
"App info doesn't contain source url"
)
)
).toEqual(true, "App info doesn't contain source url")
})

test.serial('fetches packages', async (t) => {
test('fetches packages', async () => {
const output = await parseCli(['apm', 'packages', '--debug'])

t.assert(output.includes('apm-registry'), 'Missing apm-registry')
t.assert(output.includes('apm-enssub'), 'Missing apm-enssub')
t.assert(output.includes('apm-repo'), 'Missing apm-repo')
t.assert(output.includes('aragon'), 'Missing aragon')
t.assert(output.includes('agent'), 'Missing agent')
t.assert(output.includes('finance'), 'Missing finance')
t.assert(output.includes('token-manager'), 'Missing token-manager')
t.assert(output.includes('vault'), 'Missing vault')
t.assert(output.includes('voting'), 'Missing voting')
t.assert(output.includes('bare-template'), 'Missing bare-template')
t.assert(output.includes('company-template'), 'Missing company-template')
t.assert(
output.includes('membership-template'),
expect(output.includes('apm-registry')).toEqual(true, 'Missing apm-registry')
expect(output.includes('apm-enssub')).toEqual(true, 'Missing apm-enssub')
expect(output.includes('apm-repo')).toEqual(true, 'Missing apm-repo')
expect(output.includes('aragon')).toEqual(true, 'Missing aragon')
expect(output.includes('agent')).toEqual(true, 'Missing agent')
expect(output.includes('finance')).toEqual(true, 'Missing finance')
expect(output.includes('token-manager')).toEqual(
true,
'Missing token-manager'
)
expect(output.includes('vault')).toEqual(true, 'Missing vault')
expect(output.includes('voting')).toEqual(true, 'Missing voting')
expect(output.includes('bare-template')).toEqual(
true,
'Missing bare-template'
)
expect(output.includes('company-template')).toEqual(
true,
'Missing company-template'
)
expect(output.includes('membership-template')).toEqual(
true,
'Missing membership-template'
)
})
22 changes: 11 additions & 11 deletions packages/cli/test/dao/dao-acl.test.js
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
import test from 'ava'
//
import parseCli from '../parseCli'

const daoAddressRegex = /Created DAO: (.*)\n$/

test.serial('acl view', async (t) => {
jest.setTimeout(60000)

test('acl view', async () => {
const date = new Date().getTime()
const id = `newdao${date}`

await parseCli(['dao', 'new', '--debug', '--aragon-id', id])
const stdout = await parseCli(['dao', 'acl', 'view', id, '--debug'])

t.assert(stdout.includes('App'))
t.assert(stdout.includes('Action'))
t.assert(stdout.includes('Allowed entities'))
t.assert(stdout.includes('Manager'))
t.assert(stdout.includes('CREATE_PERMISSIONS_ROLE'))
expect(stdout.includes('App')).toBe(true)
expect(stdout.includes('Action')).toBe(true)
expect(stdout.includes('Allowed entities')).toBe(true)
expect(stdout.includes('Manager')).toBe(true)
expect(stdout.includes('CREATE_PERMISSIONS_ROLE')).toBe(true)
})

test.serial('acl grant', async (t) => {
test('acl grant', async () => {
const newDaoStdout = await parseCli(['dao', 'new', '--debug'])
const daoAddress = newDaoStdout.match(daoAddressRegex)[1]

Expand All @@ -33,8 +33,8 @@ test.serial('acl grant', async (t) => {
'--debug',
])

t.assert(
stdout.includes('Successfully executed'),
expect(stdout.includes('Successfully executed')).toEqual(
true,
'Unable to grant APP_MANAGER_ROLE role'
)
})
18 changes: 9 additions & 9 deletions packages/cli/test/dao/dao-apps.test.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
import test from 'ava'
//
import parseCli from '../parseCli'

test.serial('lists apps from DAO', async (t) => {
jest.setTimeout(60000)

test('lists apps from DAO', async () => {
const date = new Date().getTime()
const id = `newdao${date}`

await parseCli(['dao', 'new', '--debug', '--aragon-id', id])
const stdout = await parseCli(['dao', 'apps', id, '--debug'])

t.assert(stdout.includes('App'))
t.assert(stdout.includes('Proxy address'))
t.assert(stdout.includes('Content'))
t.assert(stdout.includes('kernel'))
expect(stdout.includes('App')).toBe(true)
expect(stdout.includes('Proxy address')).toBe(true)
expect(stdout.includes('Content')).toBe(true)
expect(stdout.includes('kernel')).toBe(true)
})

test.serial('lists all apps from DAO', async (t) => {
test('lists all apps from DAO', async () => {
const date = new Date().getTime()
const id = `newdao${date}`

Expand All @@ -26,5 +26,5 @@ test.serial('lists all apps from DAO', async (t) => {

const stdout = await parseCli(['dao', 'apps', id, '--all', '--debug'])

t.assert(stdout.includes('Permissionless app'))
expect(stdout.includes('Permissionless app')).toBe(true)
})
8 changes: 4 additions & 4 deletions packages/cli/test/dao/dao-id-assign.test.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import test from 'ava'
//
import { runAragonCLI } from '../util'
import parseCli from '../parseCli'

const daoAddressRegex = /Created DAO: (.*)$/

test('assigns an Aragon Id to a DAO address', async (t) => {
jest.setTimeout(60000)

test('assigns an Aragon Id to a DAO address', async () => {
const { stdout: daoNewStdout } = await runAragonCLI(['dao', 'new', '--debug'])
const daoAddress = daoNewStdout.match(daoAddressRegex)[1]

Expand All @@ -19,5 +19,5 @@ test('assigns an Aragon Id to a DAO address', async (t) => {
'--debug',
])

t.true(assignIdStdout.includes('successfully assigned to'))
expect(assignIdStdout.includes('successfully assigned to')).toBe(true)
})
Loading