Skip to content

Commit

Permalink
Restore disabled tests with aws-lite testing
Browse files Browse the repository at this point in the history
Update deps
  • Loading branch information
ryanblock committed Feb 26, 2024
1 parent fe65b4e commit 97b1238
Show file tree
Hide file tree
Showing 6 changed files with 163 additions and 164 deletions.
10 changes: 5 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,13 @@
"@architect/hydrate": "~4.0.2",
"@architect/inventory": "~4.0.3",
"@architect/package": "~9.0.1",
"@architect/utils": "~4.0.2",
"@architect/utils": "~4.0.3",
"@aws-lite/apigatewayv2": "^0.0.4",
"@aws-lite/client": "^0.17.1",
"@aws-lite/client": "~0.18.0-RC.2",
"@aws-lite/cloudformation": "^0.0.4",
"@aws-lite/cloudfront": "^0.0.8",
"@aws-lite/lambda": "^0.0.5",
"@aws-lite/s3": "^0.1.18",
"@aws-lite/s3": "^0.1.19",
"@aws-lite/ssm": "^0.2.3",
"chalk": "4.1.2",
"fs-extra": "~11.2.0",
Expand All @@ -60,12 +60,12 @@
"devDependencies": {
"@architect/eslint-config": "~2.1.2",
"cross-env": "~7.0.3",
"eslint": "~8.56.0",
"eslint": "~8.57.0",
"mock-tmp": "~0.0.2",
"nyc": "~15.1.0",
"proxyquire": "~2.1.3",
"tap-arc": "~1.2.2",
"tape": "~5.7.4"
"tape": "~5.7.5"
},
"eslintConfig": {
"extends": "@architect/eslint-config"
Expand Down
13 changes: 2 additions & 11 deletions test/integration/static/index-test.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,10 @@
/* let test = require('tape')
let test = require('tape')
let { join } = require('path')
let mockTmp = require('mock-tmp')
let proxyquire = require('proxyquire')
let inventory = require('@architect/inventory')
let { updater } = require('@architect/utils')

// Necessary to run test solo
require('aws-sdk/lib/maintenance_mode_message').suppress = true
let aws = require('aws-sdk')
let awsMock = require('aws-sdk-mock')
let published
function publish (params, callback) {
published = params
Expand Down Expand Up @@ -56,18 +51,16 @@ function staticDeploy (t, cwd, callback) {
}
})
}
*/

/**
* Notes:
* - Unfortunately, proxyquire seems to have a nested file folder + `@global` bug, so we can't run this from index
* - Instead, we have to run inventory ourselves on each test, which kinda sucks
* - Also, it'd be nice to test the CloudFormation stackname code path
*/
/*
test('Set up env', t => {
t.plan(1)
t.ok(staticDeployMod, 'Static asset deployment module is present')
new aws.S3()
})

test(`Skip static deploy if @static isn't defined`, t => {
Expand Down Expand Up @@ -168,8 +161,6 @@ test(`Respect prefix setting in project manifest`, t => {

test('Teardown', t => {
t.plan(1)
awsMock.restore()
reset()
t.pass('Done')
})
*/
45 changes: 22 additions & 23 deletions test/integration/static/publish/index-test.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
/* let test = require('tape')
let test = require('tape')
let awsLite = require('@aws-lite/client')
let { join } = require('path')
let mockTmp = require('mock-tmp')
let proxyquire = require('proxyquire')
require('aws-sdk/lib/maintenance_mode_message').suppress = true
let aws = require('aws-sdk')
let awsMock = require('aws-sdk-mock')
let _inventory = require('@architect/inventory')
let { updater } = require('@architect/utils')

Expand All @@ -28,44 +26,46 @@ let sut = proxyquire(filePath, {
'./s3/delete-files': deleteFiles
})

let s3
let aws
let defaultParams = () => ({
aws,
Bucket: 'a-bucket',
folder: 'public',
inventory,
prune: false,
region: 'us-west-1',
s3,
update: updater('Deploy')
})

let arc = '@app\nan-app\n@static'
let content = 'hi there'
let cwd = mockTmp({
'app.arc': arc,
public: {
'index.html': content,
'something.json': content,
'index.js': content,
},
})

function setup () {
putted = undefined
deleted = undefined
params = defaultParams()
awsLite.testing.mock('S3.HeadObject', '')
awsLite.testing.mock('S3.PutObject', '')
awsLite.testing.mock('S3.ListObjectsV2', '')
awsLite.testing.mock('S3.DeleteObjects', '')
}

test('Set up env', async t => {
t.plan(2)
t.plan(3)
t.ok(sut, 'S3 publish module is present')

awsMock.mock('S3', 'headObject', (params, callback) => callback())
awsMock.mock('S3', 'putObject', (params, callback) => callback())
awsMock.mock('S3', 'listObjectsV2', (params, callback) => callback())
awsMock.mock('S3', 'deleteObjects', (params, callback) => callback())
s3 = new aws.S3()
aws = await awsLite({ region: 'us-west-2', plugins: [ import('@aws-lite/s3') ] })
awsLite.testing.enable()
t.ok(awsLite.testing.isEnabled(), 'AWS client testing enabled')

let cwd = mockTmp({
'app.arc': arc,
public: {
'index.html': content,
'something.json': content,
'index.js': content,
},
})
inventory = await _inventory({ cwd })
t.ok(inventory, 'Got inventory obj')
})
Expand Down Expand Up @@ -123,8 +123,7 @@ test(`Static asset deletion (deployAction is 'delete')`, t => {

test('Teardown', t => {
t.plan(1)
awsMock.restore()
mockTmp.reset()
t.pass('Done')
awsLite.testing.disable()
t.notOk(awsLite.testing.isEnabled(), 'Done')
})
*/
29 changes: 12 additions & 17 deletions test/unit/direct/deploy-test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/* let proxyquire = require('proxyquire')
let proxyquire = require('proxyquire')
let test = require('tape')
let awsLite = require('@aws-lite/client')
let { updater } = require('@architect/utils')
let inventory = require('@architect/inventory')
let { join } = require('path')
Expand All @@ -8,15 +9,10 @@ let mocks = { resources: [
{ ResourceType: 'AWS::Lambda::Function', LogicalResourceId: 'GetIndexHTTPLambda' },
] }

// Necessary to run test solo
require('aws-sdk/lib/maintenance_mode_message').suppress = true
let aws = require('aws-sdk')
let awsMock = require('aws-sdk-mock')
function fakeGetResources (params, callback) {
callback(null, mocks.resources)
}
let didHydrate
let aws, didHydrate
function fakeUpdateLambda (params, callback) {
didHydrate = params.shouldHydrate
callback()
Expand All @@ -43,6 +39,7 @@ function directDeploy (t, rawArc, lambdas, callback) {
inventory({ rawArc }, function (err, result) {
if (err) t.fail(err)
else {
params.aws = aws
params.inventory = result
params.specificLambdasToDeploy = lambdas
directDeployMod(params, err => {
Expand All @@ -53,14 +50,13 @@ function directDeploy (t, rawArc, lambdas, callback) {
})
}

test('Set up env', t => {
t.plan(1)
test('Set up env', async t => {
t.plan(2)
t.ok(directDeployMod, 'Direct deployment module is present')
awsMock.mock('CloudFormation', 'describeStacks', function (params, callback) {
callback(null, { Stacks: false })
})
new aws.CloudFormation()
aws = await awsLite({ region: 'us-west-2', plugins: [ import('@aws-lite/cloudformation') ] })
awsLite.testing.enable()
awsLite.testing.mock('CloudFormation.DescribeStacks', { Stacks: false })
t.ok(awsLite.testing.isEnabled(), 'AWS client testing enabled')
})

test('Should be able to deploy an HTTP POST function directly when a root handler function is defined', t => {
Expand Down Expand Up @@ -106,7 +102,6 @@ if (!process.platform.startsWith('win')) {

test('Teardown', t => {
t.plan(1)
awsMock.restore()
t.pass('Done')
awsLite.testing.disable()
t.notOk(awsLite.testing.isEnabled(), 'Done')
})
*/
Loading

0 comments on commit 97b1238

Please sign in to comment.