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

Restore disabled tests with aws-lite testing #386

Merged
merged 2 commits into from
Mar 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@

## [5.0.3] 2024-02-13

### Changed

- Updated dependencies


### Fixed

- Fixed issue where entirely custom Lambda-based projects may error when trying to print the project's URL(s) after deploying
Expand Down
22 changes: 11 additions & 11 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
},
"scripts": {
"test": "npm run lint && npm run test:integration && npm run coverage",
"test:unit": "cross-env tape 'test/unit/**/*-test.js' | tap-arc",
"test:unit": "cross-env AWS_ACCESS_KEY_ID=\"blah\" AWS_SECRET_ACCESS_KEY=\"blah\" tape 'test/unit/**/*-test.js' | tap-arc",
"test:slow": "cross-env tape 'test/slow/**/*-test.js' | tap-arc",
"test:integration": "cross-env AWS_ACCESS_KEY_ID=\"blah\" AWS_SECRET_ACCESS_KEY=\"blah\" tape 'test/integration/**/*-test.js' | tap-arc",
"coverage": "nyc --reporter=lcov --reporter=text npm run test:unit",
Expand All @@ -32,17 +32,17 @@
},
"homepage": "https://github.com/architect/deploy#readme",
"dependencies": {
"@architect/create": "~5.0.1",
"@architect/hydrate": "~4.0.2",
"@architect/inventory": "~4.0.3",
"@architect/package": "~9.0.1",
"@architect/utils": "~4.0.2",
"@architect/create": "~5.0.2",
"@architect/hydrate": "~4.0.3",
"@architect/inventory": "~4.0.4",
"@architect/package": "~9.0.2",
"@architect/utils": "~4.0.4",
"@aws-lite/apigatewayv2": "^0.0.4",
"@aws-lite/client": "^0.17.1",
"@aws-lite/client": "~0.20.0",
"@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.20",
"@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",
"mock-tmp": "~0.0.2",
"eslint": "~8.57.0",
"mock-tmp": "~0.0.3",
"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
Loading