Skip to content

Commit

Permalink
chore: enable more tests (#808)
Browse files Browse the repository at this point in the history
Reenable tests that were not running.
  • Loading branch information
peternhale committed Jan 31, 2022
1 parent 6e93f57 commit db03bd0
Show file tree
Hide file tree
Showing 23 changed files with 446 additions and 326 deletions.
17 changes: 15 additions & 2 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ version: 2.1

orbs:
release-management: salesforce/npm-release-management@4
aws-cli: circleci/aws-cli@2.0

jobs:
lint: &lint
Expand Down Expand Up @@ -40,9 +41,14 @@ jobs:
- restore_cache: *restore_cache
- attach_workspace: {at: node_modules}
- run: .circleci/setup_git
- run: |
apt-get update
apt-get install -y p7zip-full \
osslsigncode \
nsis
- run: yarn exec nps test
- store_test_results:
path: ~/cli/reports
path: /root/project/cli/reports
node-devcli: &node-devcli
docker:
- image: node:latest
Expand Down Expand Up @@ -85,12 +91,16 @@ workflows:
- compile-typescript
- node-devcli
- test:
context: AWS
matrix:
parameters:
image: [node:latest, node:16, node:14]
name: test-<< matrix.image >>
requires: [lint, compile-typescript]
- release-management/release-package:
context:
- SF-CLI-RELEASE-PROCESS
- AWS
github-release: true
requires:
- lint
Expand All @@ -110,4 +120,7 @@ workflows:
only:
- main
jobs:
- release-management/dependabot-automerge
- release-management/dependabot-automerge:
context:
- SF-CLI-RELEASE-PROCESS
- AWS
9 changes: 5 additions & 4 deletions package-scripts.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@ const path = require('path')
sh.set('-e')

setColors(['dim'])

const testTypes = ['']
process.env.TEST_SERIES = '1'
const testTypes = ['', 'integration']
const tests = testTypes.map(cmd => {
const {silent} = sh.config
sh.config.silent = true
const mocha = 'mocha --forbid-only'
const base = path.join('test/commands', cmd)
const base = cmd === 'integration' ? path.join('test', cmd) : path.join('test/commands', cmd)
sh.pushd(base)
let tests = _(sh.ls())
.map(t => [t.split('.')[0], path.join(base, t)])
Expand All @@ -30,6 +30,7 @@ const tests = testTypes.map(cmd => {
if (process.env.CIRCLECI) {
tests = series(mkdirp('reports'), tests)
}

sh.config.silent = silent
return [cmd, series('nps build', tests)]
})
Expand All @@ -45,6 +46,6 @@ module.exports = {
},
test: Object.assign({
default: series.nps(...testTypes.map(t => `test.${t}`)),
}, _.fromPairs(tests)),
}, Object.fromEntries(tests)),
},
}
17 changes: 10 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@
"dependencies": {
"@oclif/core": "^1.2.0",
"@oclif/plugin-help": "^5.1.10",
"@oclif/plugin-not-found": "^2.2.3",
"@oclif/plugin-warn-if-update-available": "^2.0.3",
"@oclif/plugin-not-found": "^2.2.4",
"@oclif/plugin-warn-if-update-available": "^2.0.4",
"aws-sdk": "^2.1064.0",
"debug": "^4.3.3",
"find-yarn-workspace-root": "^2.0.0",
"fs-extra": "^8.1",
Expand Down Expand Up @@ -43,7 +44,6 @@
"@types/write-json-file": "^3.2.1",
"@types/yeoman-generator": "^5.2.8",
"@types/yosay": "^2.0.1",
"aws-sdk": "^2.1048.0",
"chai": "^4.2.0",
"conventional-changelog-cli": "^2.2.2",
"eslint": "^7.3.2",
Expand All @@ -58,7 +58,7 @@
"shelljs": "^0.8.5",
"shx": "^0.3.3",
"tmp": "^0.2.1",
"ts-node": "^9.0.0",
"ts-node": "^10.4.0",
"typescript": "4.5.4"
},
"resolutions": {
Expand Down Expand Up @@ -93,8 +93,7 @@
"dirname": "oclif",
"topicSeparator": " ",
"macos": {
"identifier": "com.oclif.cli",
"sign": "Developer ID Installer: Heroku INC"
"identifier": "com.salesforce.cli"
},
"update": {
"autoupdate": {
Expand All @@ -105,7 +104,11 @@
"version": "12.12.0"
},
"s3": {
"bucket": "oclif-staging",
"bucket": "dfc-data-production",
"indexVersionLimit": 20,
"folder": "media/salesforce-cli/oclif-testing",
"acl": " ",
"host": "https://developer.salesforce.com",
"xz": true
}
},
Expand Down
14 changes: 14 additions & 0 deletions src/aws.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,20 @@ export default {
else resolve(data)
})
}),
listObjects: (options: S3.Types.ListObjectsV2Request) => new Promise<S3.ListObjectsV2Output>((resolve, reject) => {
debug('listObjects', `s3://${options.Bucket}/${options.Prefix}`)
aws.s3.listObjectsV2(options, (err, objects) => {
if (err) reject(err)
resolve(objects)
})
}),
deleteObjects: (options: S3.Types.DeleteObjectsRequest) => new Promise<S3.DeleteObjectsOutput>((resolve, reject) => {
debug('deleteObjects', `s3://${options.Bucket}`)
aws.s3.deleteObjects(options, (err, deletedObjects) => {
if (err) reject(err)
resolve(deletedObjects)
})
}),
}
},
}
Expand Down
2 changes: 1 addition & 1 deletion src/commands/promote.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {Command, Flags, CliUx} from '@oclif/core'
import {CliUx, Command, Flags} from '@oclif/core'
import * as path from 'path'

import aws from '../aws'
Expand Down
2 changes: 1 addition & 1 deletion src/tarballs/config.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {Interfaces, Config, CliUx} from '@oclif/core'
import {CliUx, Interfaces, Config} from '@oclif/core'

import * as path from 'path'
import * as qq from 'qqjs'
Expand Down
1 change: 1 addition & 0 deletions test/commands/generate/command.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
require('../../run')(module.filename)
1 change: 1 addition & 0 deletions test/commands/generate/hook.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
require('../../run')(module.filename)
45 changes: 0 additions & 45 deletions test/deb.test.ts

This file was deleted.

9 changes: 9 additions & 0 deletions test/helpers/helper.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import {deleteFolder} from './helper'
import {expect} from '@oclif/test'

describe('helper', () => {
it('should not do a recursive list', async () => {
const list = await deleteFolder('dfc-data-production', 'media/salesforce-cli/oclif-testing/versions')
expect(list).to.be.ok
})
})
39 changes: 39 additions & 0 deletions test/helpers/helper.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import * as qq from 'qqjs'
import {expect} from '@oclif/test'
import {gitSha} from '../../src/tarballs'
import * as shelljs from 'shelljs'
import * as S3 from 'aws-sdk/clients/s3'
import aws from '../../src/aws'

export const oclifTestingVersionsURI = 'media/salesforce-cli/oclif-testing/versions'
export const oclifTestingChannelsURI = 'media/salesforce-cli/oclif-testing/channels'
export const developerSalesforceCom = 'developer.salesforce.com'

export const findDistFileSha = async (cwd: string, platform: string, filter: (f: string) => boolean): Promise<string[]> => {
const distFiles = await qq.ls(`${cwd}/dist/${platform}/`)
const pkg = distFiles.find(element => filter(element)) as string
expect(pkg).to.be.ok
return [pkg, await gitSha(process.cwd(), {short: true})]
}

export function gitShaSync(cwd: string, options: {short?: boolean} = {}): string {
const args = options.short ? ['rev-parse', '--short', 'HEAD'] : ['rev-parse', 'HEAD']
const r = shelljs.exec(`git ${args.join(' ')}`, {cwd})
return r.stdout
}

export async function deleteFolder(bucket: string, folder: string): Promise<(string | undefined)[]> {
const foundObjects = await aws.s3.listObjects({Bucket: bucket, Prefix: folder})
const foundKeys = foundObjects.Contents?.map(o => o.Key)
if (foundKeys && foundKeys.length > 0) {
const deleteObjectsRequest: S3.Types.DeleteObjectsRequest = {
Bucket: bucket,
Delete: {Objects: foundKeys!.map(k => ({Key: k} as S3.ObjectIdentifier))},
}
const deletedObjects = await aws.s3.deleteObjects(deleteObjectsRequest)
return deletedObjects?.Deleted ? deletedObjects.Deleted.map(o => o.Key) : []
}

return []
}

50 changes: 50 additions & 0 deletions test/integration/deb.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import {expect, test} from '@oclif/test'
import * as qq from 'qqjs'
import {deleteFolder, developerSalesforceCom} from '../helpers/helper'
import {gitSha} from '../../src/tarballs'

const pjson = require('../../package.json')
const pjsonPath = require.resolve('../../package.json')
const originalVersion = pjson.version
const target = [process.platform, process.arch].join('-')

const onlyLinux = process.platform === 'linux' ? test : test.skip()
const testRun = `test-${Math.random().toString().split('.')[1].slice(0, 4)}`

// 2022-01 - this test requires linux with apt-ftparchive installed. Current CircleCi images do not have that util installed - skipping test
describe.skip('publish:deb', () => {
let bucket: string
let basePrefix: string

beforeEach(async () => {
pjson.version = `${pjson.version}-${testRun}`
bucket = pjson.oclif.update.s3.bucket
basePrefix = pjson.oclif.update.s3.folder
await deleteFolder(bucket, `${basePrefix}/versions/${pjson.version}/`)
await qq.writeJSON(pjsonPath, pjson)
const root = qq.join(__dirname, '../tmp/test/publish')
await qq.emptyDir(root)
qq.cd(root)
})
afterEach(async () => {
await deleteFolder(bucket, `${basePrefix}/versions/${pjson.version}/`)
qq.cd([__dirname, '..'])
pjson.version = originalVersion
await qq.writeJSON(pjsonPath, pjson)
})

onlyLinux
.command(['pack:deb'])
.command(['upload:deb'])
.it('publishes valid releases', async () => {
const sha = await gitSha(process.cwd(), {short: true})
qq.cd([__dirname, '..', '..'])
await qq.x('cat test/release.key | apt-key add -')
await qq.x(`echo "deb https://${developerSalesforceCom}/apt ./" > /etc/apt/sources.list.d/oclif-dev.list`)
await qq.x('apt-get update')
await qq.x('apt-get install -y oclif-dev')
await qq.x('oclif --version')
const stdout = await qq.x.stdout('oclif', ['--version'])
expect(stdout).to.contain(`oclif/${pjson.version}.${sha} ${target} node-v${pjson.oclif.update.node.version}`)
})
})
44 changes: 44 additions & 0 deletions test/integration/macos.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import {test} from '@oclif/test'
import * as qq from 'qqjs'
import {findDistFileSha, developerSalesforceCom, deleteFolder} from '../helpers/helper'

const pjson = require('../../package.json')
const pjsonPath = require.resolve('../../package.json')
const originalVersion = pjson.version

const onlyMacos = process.platform === 'darwin' ? test : test.skip()
const testRun = `test-${Math.random().toString().split('.')[1].slice(0, 4)}`

describe('publish:macos', () => {
const cwd = process.cwd()
let pkg: string
let sha: string
let bucket: string
let basePrefix: string
beforeEach(async () => {
pjson.version = `${pjson.version}-${testRun}`
bucket = pjson.oclif.update.s3.bucket
basePrefix = pjson.oclif.update.s3.folder
await deleteFolder(bucket, `${basePrefix}/versions/${pjson.version}/`)
await qq.writeJSON(pjsonPath, pjson)
const root = qq.join(__dirname, '../tmp/test/publish')
await qq.emptyDir(root)
qq.cd(root)
})
afterEach(async () => {
await deleteFolder(bucket, `${basePrefix}/versions/${pjson.version}/`)
qq.cd([__dirname, '..'])
pjson.version = originalVersion
await qq.writeJSON(pjsonPath, pjson)
})

onlyMacos
.command(['pack:macos'])
.do(async () => {
[pkg, sha] = await findDistFileSha(cwd, 'macos', f => f.endsWith('pkg'))
})
.command(['upload:macos'])
.it('publishes valid releases', async () => {
await qq.download(`https://${developerSalesforceCom}/${basePrefix}/versions/${pjson.version}/${sha}/${pkg}`)
})
})
File renamed without changes.

0 comments on commit db03bd0

Please sign in to comment.