@adobe/aio-lib-web 4.1.2 → 5.1.0-pre.2022-06-02.59001447
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.github/workflows/daily.yml +34 -0
- package/.github/workflows/node.js.yml +3 -1
- package/.github/workflows/prerelease.yml +45 -0
- package/e2e/README.md +9 -0
- package/e2e/e2e.js +111 -0
- package/e2e/env.sample +2 -0
- package/e2e/jest.config.js +16 -0
- package/e2e/sample-app/index.html +13 -0
- package/e2e/sample-app/index.js +1 -0
- package/lib/{getTvmCreds.js → getS3Creds.js} +18 -16
- package/lib/remote-storage.js +0 -1
- package/package.json +17 -13
- package/src/build-web.js +12 -9
- package/src/bundle.js +20 -18
- package/src/deploy-web.js +5 -18
- package/src/undeploy-web.js +2 -2
- package/test/__mocks__/@adobe/aio-lib-core-tvm.js +1 -1
- package/test/__mocks__/{parcel-bundler.js → @parcel/core.js} +22 -22
- package/test/lib/getS3Creds.test.js +73 -0
- package/test/src/build-web.test.js +13 -1
- package/test/src/bundle.test.js +39 -22
- package/test/src/deploy-web.test.js +106 -56
- package/test/src/undeploy-web.test.js +35 -22
- package/test/lib/getTvmCreds.test.js +0 -39
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
name: Daily - Do npm install and run all unit tests
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
schedule:
|
|
5
|
+
# run daily at midnight
|
|
6
|
+
- cron: '0 0 * * *'
|
|
7
|
+
|
|
8
|
+
jobs:
|
|
9
|
+
build:
|
|
10
|
+
runs-on: ${{ matrix.os }}
|
|
11
|
+
strategy:
|
|
12
|
+
matrix:
|
|
13
|
+
node: [14]
|
|
14
|
+
os: [ubuntu-latest]
|
|
15
|
+
|
|
16
|
+
steps:
|
|
17
|
+
- uses: actions/checkout@v2
|
|
18
|
+
- name: Use Node.js ${{ matrix.node-version }}
|
|
19
|
+
uses: actions/setup-node@v1
|
|
20
|
+
with:
|
|
21
|
+
node-version: ${{ matrix.node-version }}
|
|
22
|
+
- run: npm i --package-lock --package-lock-only
|
|
23
|
+
- run: npm ci
|
|
24
|
+
- name: run unit tests
|
|
25
|
+
run: npm run test
|
|
26
|
+
- name: Slack Notification
|
|
27
|
+
if: ${{ failure() }}
|
|
28
|
+
uses: rtCamp/action-slack-notify@v2
|
|
29
|
+
env:
|
|
30
|
+
SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK }}
|
|
31
|
+
SLACK_TITLE: 'Node version'
|
|
32
|
+
SLACK_MESSAGE: ${{ matrix.node }}
|
|
33
|
+
SLACK_COLOR: ${{ job.status == 'success' && 'good' || job.status == 'cancelled' && '#808080' || 'danger' }}
|
|
34
|
+
|
|
@@ -14,11 +14,13 @@ jobs:
|
|
|
14
14
|
runs-on: ${{ matrix.os }}
|
|
15
15
|
strategy:
|
|
16
16
|
matrix:
|
|
17
|
-
node-version: [
|
|
17
|
+
node-version: [12.x, 14.x]
|
|
18
18
|
os: [ubuntu-latest, windows-latest]
|
|
19
19
|
|
|
20
20
|
steps:
|
|
21
21
|
- uses: actions/checkout@v2
|
|
22
|
+
with:
|
|
23
|
+
fetch-depth: 0
|
|
22
24
|
- name: Use Node.js ${{ matrix.node-version }}
|
|
23
25
|
uses: actions/setup-node@v1
|
|
24
26
|
with:
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
name: publish-prerelease
|
|
2
|
+
on:
|
|
3
|
+
workflow_dispatch:
|
|
4
|
+
inputs:
|
|
5
|
+
pre-release-tag:
|
|
6
|
+
description: 'The pre-release tag use in the version'
|
|
7
|
+
required: false
|
|
8
|
+
default: 'pre'
|
|
9
|
+
dist-tag:
|
|
10
|
+
description: 'The dist-tag use'
|
|
11
|
+
required: false
|
|
12
|
+
default: 'next'
|
|
13
|
+
dependencies-to-update:
|
|
14
|
+
description: 'csv of dependencies to update with the dist-tag'
|
|
15
|
+
required: false
|
|
16
|
+
default: '@adobe/aio-lib-core-config,@adobe/aio-lib-core-logging,@adobe/aio-lib-core-tvm'
|
|
17
|
+
|
|
18
|
+
jobs:
|
|
19
|
+
checkout:
|
|
20
|
+
name: checkout
|
|
21
|
+
runs-on: ubuntu-latest
|
|
22
|
+
steps:
|
|
23
|
+
- uses: actions/checkout@v2
|
|
24
|
+
- run: |
|
|
25
|
+
git config user.name github-actions
|
|
26
|
+
git config user.email github-actions@github.com
|
|
27
|
+
- uses: actions/setup-node@v1
|
|
28
|
+
with:
|
|
29
|
+
node-version: 16
|
|
30
|
+
- run: |
|
|
31
|
+
npm install
|
|
32
|
+
npm test
|
|
33
|
+
- name: Update your package.json with an npm pre-release version
|
|
34
|
+
id: pre-release-version
|
|
35
|
+
uses: adobe/update-prerelease-npm-version@v1.0.0
|
|
36
|
+
with:
|
|
37
|
+
pre-release-tag: ${{ github.event.inputs.pre-release-tag }}
|
|
38
|
+
dependencies-to-update: ${{ github.event.inputs.dependencies-to-update }}
|
|
39
|
+
dependencies-to-update-version-tag: ${{ github.event.inputs.dist-tag }}
|
|
40
|
+
- run: echo pre-release-version - ${{ steps.pre-release-version.outputs.pre-release-version }}
|
|
41
|
+
- uses: JS-DevTools/npm-publish@v1
|
|
42
|
+
with:
|
|
43
|
+
token: ${{ secrets.ADOBE_BOT_NPM_TOKEN }}
|
|
44
|
+
tag: ${{ github.event.inputs.dist-tag }}
|
|
45
|
+
access: 'public'
|
package/e2e/README.md
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
# E2E Tests
|
|
2
|
+
The e2e tests require the following env vars
|
|
3
|
+
- `RUNTIME_NAMESPACE`
|
|
4
|
+
- `RUNTIME_AUTH`
|
|
5
|
+
|
|
6
|
+
The tests include
|
|
7
|
+
- Test bundler output with default settings
|
|
8
|
+
- Test deployment to CDN with default settings
|
|
9
|
+
- Test undeploy and check if assets are removed from CDN
|
package/e2e/e2e.js
ADDED
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright 2021 Adobe. All rights reserved.
|
|
3
|
+
This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
you may not use this file except in compliance with the License. You may obtain a copy
|
|
5
|
+
of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
6
|
+
|
|
7
|
+
Unless required by applicable law or agreed to in writing, software distributed under
|
|
8
|
+
the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
9
|
+
OF ANY KIND, either express or implied. See the License for the specific language
|
|
10
|
+
governing permissions and limitations under the License.
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
const path = require('path')
|
|
14
|
+
const fs = require('fs-extra')
|
|
15
|
+
const fetch = require('node-fetch')
|
|
16
|
+
|
|
17
|
+
jest.setTimeout(30000)
|
|
18
|
+
|
|
19
|
+
// load .env values in the e2e folder, if any
|
|
20
|
+
require('dotenv').config({ path: path.join(__dirname, '.env') })
|
|
21
|
+
|
|
22
|
+
const bundle = require('../src/bundle')
|
|
23
|
+
const deployWeb = require('../src/deploy-web')
|
|
24
|
+
const undeployWeb = require('../src/undeploy-web')
|
|
25
|
+
const ENTRY_FILE = path.join(__dirname, 'sample-app/index.html')
|
|
26
|
+
const DEST_FOLDER = path.join(__dirname, 'dist/')
|
|
27
|
+
const CACHE_FILE = path.join(__dirname, '.cache')
|
|
28
|
+
const SRC_REGEX = /<script.*src="(?<src>.*?)"/
|
|
29
|
+
|
|
30
|
+
const config = {
|
|
31
|
+
app: {
|
|
32
|
+
hasFrontend: true,
|
|
33
|
+
hostname: 'adobeio-static.net'
|
|
34
|
+
},
|
|
35
|
+
s3: {
|
|
36
|
+
tvmUrl: 'https://firefly-tvm.adobe.io', // default tvm url
|
|
37
|
+
credsCacheFile: CACHE_FILE,
|
|
38
|
+
folder: process.env.RUNTIME_NAMESPACE
|
|
39
|
+
},
|
|
40
|
+
ow: {
|
|
41
|
+
namespace: process.env.RUNTIME_NAMESPACE,
|
|
42
|
+
auth: process.env.RUNTIME_AUTH
|
|
43
|
+
},
|
|
44
|
+
web: {
|
|
45
|
+
distProd: DEST_FOLDER
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
beforeAll(async () => {
|
|
50
|
+
jest.setTimeout(240000)
|
|
51
|
+
})
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* Test bundler
|
|
55
|
+
*/
|
|
56
|
+
describe('e2e', () => {
|
|
57
|
+
let url
|
|
58
|
+
|
|
59
|
+
test('check bundle output dir', async () => {
|
|
60
|
+
let error
|
|
61
|
+
let parcelBundle
|
|
62
|
+
try {
|
|
63
|
+
parcelBundle = await bundle(
|
|
64
|
+
ENTRY_FILE,
|
|
65
|
+
DEST_FOLDER,
|
|
66
|
+
{}
|
|
67
|
+
)
|
|
68
|
+
await parcelBundle.run()
|
|
69
|
+
} catch (e) {
|
|
70
|
+
error = e
|
|
71
|
+
console.error(e)
|
|
72
|
+
}
|
|
73
|
+
expect(error).toBeUndefined()
|
|
74
|
+
expect(fs.existsSync(path.join(DEST_FOLDER, 'index.html'))).toBe(true)
|
|
75
|
+
|
|
76
|
+
const html = fs.readFileSync(path.join(DEST_FOLDER, 'index.html'), 'utf8')
|
|
77
|
+
const { src } = SRC_REGEX.exec(html).groups
|
|
78
|
+
expect(src).not.toBeNull()
|
|
79
|
+
expect(fs.existsSync(path.join(DEST_FOLDER, src))).toBe(true)
|
|
80
|
+
expect(fs.existsSync(path.join(DEST_FOLDER, `${src}.map`))).toBe(true)
|
|
81
|
+
})
|
|
82
|
+
|
|
83
|
+
test('bundle and deploy test ui', async () => {
|
|
84
|
+
let error, contents
|
|
85
|
+
try {
|
|
86
|
+
url = await deployWeb(config)
|
|
87
|
+
const response = await fetch(url)
|
|
88
|
+
contents = await response.text()
|
|
89
|
+
} catch (e) {
|
|
90
|
+
error = e
|
|
91
|
+
console.error(e)
|
|
92
|
+
}
|
|
93
|
+
expect(error).toBeUndefined()
|
|
94
|
+
expect(url).not.toBeNull()
|
|
95
|
+
expect(contents).not.toBeNull()
|
|
96
|
+
expect(contents).toEqual(fs.readFileSync(path.join(DEST_FOLDER, 'index.html'), 'utf8'))
|
|
97
|
+
})
|
|
98
|
+
|
|
99
|
+
test('undeploy', async () => {
|
|
100
|
+
let error, response
|
|
101
|
+
try {
|
|
102
|
+
await undeployWeb(config)
|
|
103
|
+
response = await fetch(url)
|
|
104
|
+
} catch (e) {
|
|
105
|
+
error = e
|
|
106
|
+
console.error(e)
|
|
107
|
+
}
|
|
108
|
+
expect(error).toBeUndefined()
|
|
109
|
+
expect(response.status).toEqual(404)
|
|
110
|
+
})
|
|
111
|
+
})
|
package/e2e/env.sample
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright 2021 Adobe. All rights reserved.
|
|
3
|
+
This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
you may not use this file except in compliance with the License. You may obtain a copy
|
|
5
|
+
of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
6
|
+
|
|
7
|
+
Unless required by applicable law or agreed to in writing, software distributed under
|
|
8
|
+
the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
9
|
+
OF ANY KIND, either express or implied. See the License for the specific language
|
|
10
|
+
governing permissions and limitations under the License.
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
module.exports = {
|
|
14
|
+
testEnvironment: 'node',
|
|
15
|
+
verbose: true
|
|
16
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
<!DOCTYPE html>
|
|
2
|
+
<html lang="en">
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="UTF-8">
|
|
5
|
+
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
|
6
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
7
|
+
<title>Document</title>
|
|
8
|
+
</head>
|
|
9
|
+
<body>
|
|
10
|
+
<h1>Hello World</h1>
|
|
11
|
+
<script src="./index.js"></script>
|
|
12
|
+
</body>
|
|
13
|
+
</html>
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
console.log('Hello')
|
|
@@ -11,30 +11,32 @@ governing permissions and limitations under the License.
|
|
|
11
11
|
*/
|
|
12
12
|
const TvmClient = require('@adobe/aio-lib-core-tvm')
|
|
13
13
|
|
|
14
|
-
const
|
|
15
|
-
if (
|
|
16
|
-
|
|
14
|
+
const getS3Credentials = async (config) => {
|
|
15
|
+
if (
|
|
16
|
+
// byo
|
|
17
|
+
!(config.s3 && config.s3.creds) &&
|
|
18
|
+
// ootb
|
|
19
|
+
!(config.ow && config.ow.namespace && config.ow.auth)
|
|
20
|
+
) {
|
|
21
|
+
throw new Error('Please check your .env file to ensure your credentials are correct. You can also use "aio app use" to load/refresh your credentials')
|
|
17
22
|
}
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
if (!apiUrl) {
|
|
22
|
-
throw new Error('Missing required argument `apiUrl`')
|
|
23
|
-
}
|
|
24
|
-
if (!cacheFile) {
|
|
25
|
-
throw new Error('Missing required argument `cacheFile`')
|
|
23
|
+
|
|
24
|
+
if (config.s3 && config.s3.creds) {
|
|
25
|
+
return config.s3.creds
|
|
26
26
|
}
|
|
27
27
|
|
|
28
28
|
const client = await TvmClient.init({
|
|
29
29
|
ow: {
|
|
30
|
-
namespace,
|
|
31
|
-
auth
|
|
30
|
+
namespace: config.ow.namespace,
|
|
31
|
+
auth: config.ow.auth
|
|
32
32
|
},
|
|
33
|
-
|
|
34
|
-
|
|
33
|
+
// can be undefined => defaults in TvmClient
|
|
34
|
+
apiUrl: config.s3 && config.s3.tvmUrl,
|
|
35
|
+
cacheFile: config.s3 && config.s3.credsCacheFile
|
|
35
36
|
})
|
|
37
|
+
|
|
36
38
|
const creds = await client.getAwsS3Credentials()
|
|
37
39
|
return creds
|
|
38
40
|
}
|
|
39
41
|
|
|
40
|
-
module.exports =
|
|
42
|
+
module.exports = getS3Credentials
|
package/lib/remote-storage.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@adobe/aio-lib-web",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "5.1.0-pre.2022-06-02.59001447",
|
|
4
4
|
"description": "Utility tooling library to build and deploy Adobe I/O Project Firefly app static sites to CDN",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"directories": {
|
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
"author": "Adobe Inc.",
|
|
11
11
|
"license": "Apache-2.0",
|
|
12
12
|
"engines": {
|
|
13
|
-
"node": ">=
|
|
13
|
+
"node": ">=12.2.0"
|
|
14
14
|
},
|
|
15
15
|
"repository": "adobe/aio-lib-web",
|
|
16
16
|
"homepage": "https://github.com/adobe/aio-lib-web",
|
|
@@ -25,12 +25,13 @@
|
|
|
25
25
|
"beautify": "npm run lint -- --fix",
|
|
26
26
|
"test": "npm run unit-test && npm run lint",
|
|
27
27
|
"unit-test": "jest --forceExit --detectOpenHandles -c ./jest.config.js",
|
|
28
|
-
"generate-jsdoc": "jsdoc2md -f index.js > doc/api.md"
|
|
28
|
+
"generate-jsdoc": "jsdoc2md -f index.js > doc/api.md",
|
|
29
|
+
"e2e": "jest --config='./e2e/jest.config.js' --testRegex './e2e/e2e.js'"
|
|
29
30
|
},
|
|
30
31
|
"dependencies": {
|
|
31
|
-
"@adobe/aio-lib-core-config": "
|
|
32
|
-
"@adobe/aio-lib-core-logging": "
|
|
33
|
-
"@adobe/aio-lib-core-tvm": "
|
|
32
|
+
"@adobe/aio-lib-core-config": "next",
|
|
33
|
+
"@adobe/aio-lib-core-logging": "next",
|
|
34
|
+
"@adobe/aio-lib-core-tvm": "next",
|
|
34
35
|
"aws-sdk": "^2.600.0",
|
|
35
36
|
"fs-extra": "^9.0.0",
|
|
36
37
|
"joi": "^17.2.1",
|
|
@@ -38,20 +39,23 @@
|
|
|
38
39
|
"klaw": "^3.0.0",
|
|
39
40
|
"lodash.clonedeep": "^4.5.0",
|
|
40
41
|
"mime-types": "^2.1.24",
|
|
41
|
-
"parcel
|
|
42
|
+
"parcel": "2.5.0",
|
|
43
|
+
"regenerator-runtime": "^0.13.7"
|
|
42
44
|
},
|
|
43
45
|
"devDependencies": {
|
|
44
46
|
"@types/hapi__joi": "^16.0.2",
|
|
45
47
|
"@types/jest": "^25.1.0",
|
|
46
|
-
"eslint": "^
|
|
48
|
+
"eslint": "^7",
|
|
47
49
|
"eslint-config-standard": "^14.1.0",
|
|
48
50
|
"eslint-plugin-import": "^2.18.2",
|
|
49
51
|
"eslint-plugin-jest": "^23.1.1",
|
|
50
52
|
"eslint-plugin-node": "^11.0.0",
|
|
51
53
|
"eslint-plugin-promise": "^4.2.1",
|
|
52
54
|
"eslint-plugin-standard": "^4.0.1",
|
|
53
|
-
"jest": "^
|
|
54
|
-
"jsdoc-to-markdown": "^
|
|
55
|
-
"memfs": "^3.0.1"
|
|
56
|
-
|
|
57
|
-
}
|
|
55
|
+
"jest": "^27",
|
|
56
|
+
"jsdoc-to-markdown": "^7",
|
|
57
|
+
"memfs": "^3.0.1",
|
|
58
|
+
"node-fetch": "^2.6.1"
|
|
59
|
+
},
|
|
60
|
+
"prereleaseSha": "590014478f3c4b46555a58166d80f2b7e7cb4763"
|
|
61
|
+
}
|
package/src/build-web.js
CHANGED
|
@@ -12,7 +12,7 @@ governing permissions and limitations under the License.
|
|
|
12
12
|
|
|
13
13
|
const fs = require('fs-extra')
|
|
14
14
|
const path = require('path')
|
|
15
|
-
const Bundler = require('parcel
|
|
15
|
+
const Bundler = require('@parcel/core').default
|
|
16
16
|
|
|
17
17
|
/**
|
|
18
18
|
* @deprecated since 4.1.0 ( January, 2021 ), use `bundle` instead
|
|
@@ -29,16 +29,19 @@ const buildWeb = async (config, log) => {
|
|
|
29
29
|
await fs.emptyDir(dist)
|
|
30
30
|
|
|
31
31
|
// 2. build files
|
|
32
|
-
const bundler = new Bundler(
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
32
|
+
const bundler = new Bundler({
|
|
33
|
+
entries: path.join(src, 'index.html'),
|
|
34
|
+
defaultConfig: require.resolve('@parcel/config-default'),
|
|
35
|
+
shouldDisableCache: true,
|
|
36
|
+
defaultTargetOptions: {
|
|
37
|
+
distDir: dist,
|
|
38
|
+
publicUrl: './'
|
|
39
|
+
},
|
|
40
|
+
logLevel: 'none',
|
|
41
|
+
shouldContentHash: true
|
|
39
42
|
})
|
|
40
43
|
|
|
41
|
-
await bundler.
|
|
44
|
+
await bundler.run()
|
|
42
45
|
|
|
43
46
|
// 3. show built files ( if we are passed a log function )
|
|
44
47
|
const files = await fs.readdir(dist)
|
package/src/bundle.js
CHANGED
|
@@ -10,7 +10,7 @@ OF ANY KIND, either express or implied. See the License for the specific languag
|
|
|
10
10
|
governing permissions and limitations under the License.
|
|
11
11
|
*/
|
|
12
12
|
|
|
13
|
-
const Bundler = require('parcel
|
|
13
|
+
const Bundler = require('@parcel/core').default
|
|
14
14
|
const aioLogger = require('@adobe/aio-lib-core-logging')('@adobe/aio-lib-web:bundle', { provider: 'debug' })
|
|
15
15
|
const fs = require('fs-extra')
|
|
16
16
|
/**
|
|
@@ -37,7 +37,7 @@ const fs = require('fs-extra')
|
|
|
37
37
|
* @param {Function} [log] the app logger
|
|
38
38
|
* @returns {BundleWebObject} the BundleWebObject
|
|
39
39
|
*/
|
|
40
|
-
module.exports = async (entryFile, dest, options = {}, log = () => {}) => {
|
|
40
|
+
module.exports = async (entryFile, dest, options = { shouldOptimize: false }, log = () => {}) => {
|
|
41
41
|
aioLogger.debug(`bundle options: ${JSON.stringify(options, null, 2)}`)
|
|
42
42
|
|
|
43
43
|
if (!entryFile || !fs.existsSync(entryFile)) {
|
|
@@ -49,26 +49,28 @@ module.exports = async (entryFile, dest, options = {}, log = () => {}) => {
|
|
|
49
49
|
|
|
50
50
|
// set defaults, but allow override by passed in values
|
|
51
51
|
const parcelBundleOptions = {
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
52
|
+
entries: entryFile,
|
|
53
|
+
defaultConfig: require.resolve('@parcel/config-default'),
|
|
54
|
+
shouldDisableCache: false,
|
|
55
|
+
targets: {
|
|
56
|
+
webassets: {
|
|
57
|
+
includeNodeModules: true,
|
|
58
|
+
distDir: dest
|
|
59
|
+
}
|
|
60
|
+
},
|
|
61
|
+
defaultTargetOptions: {
|
|
62
|
+
distDir: dest,
|
|
63
|
+
shouldOptimize: options.shouldOptimize
|
|
64
|
+
},
|
|
65
|
+
shouldPatchConsole: false,
|
|
66
|
+
shouldContentHash: true,
|
|
67
|
+
logLevel: 'error',
|
|
58
68
|
...options
|
|
59
69
|
}
|
|
60
70
|
|
|
61
71
|
aioLogger.debug(`bundle bundleOptions: ${JSON.stringify(parcelBundleOptions, null, 2)}`)
|
|
62
72
|
log(`bundling ${entryFile}`)
|
|
63
|
-
const bundler = new Bundler(
|
|
73
|
+
const bundler = new Bundler(parcelBundleOptions)
|
|
64
74
|
|
|
65
|
-
|
|
66
|
-
aioLogger.debug('cleanup bundler...')
|
|
67
|
-
await bundler.stop()
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
return {
|
|
71
|
-
bundler,
|
|
72
|
-
cleanup
|
|
73
|
-
}
|
|
75
|
+
return bundler
|
|
74
76
|
}
|
package/src/deploy-web.js
CHANGED
|
@@ -11,7 +11,7 @@ governing permissions and limitations under the License.
|
|
|
11
11
|
*/
|
|
12
12
|
|
|
13
13
|
const RemoteStorage = require('../lib/remote-storage')
|
|
14
|
-
const
|
|
14
|
+
const getS3Credentials = require('../lib/getS3Creds')
|
|
15
15
|
|
|
16
16
|
const fs = require('fs-extra')
|
|
17
17
|
const path = require('path')
|
|
@@ -20,19 +20,7 @@ const deployWeb = async (config, log) => {
|
|
|
20
20
|
if (!config || !config.app || !config.app.hasFrontend) {
|
|
21
21
|
throw new Error('cannot deploy web, app has no frontend or config is invalid')
|
|
22
22
|
}
|
|
23
|
-
|
|
24
|
-
throw new Error('missing credentials or tvmUrl+credsCacheFile in config.s3')
|
|
25
|
-
} else {
|
|
26
|
-
if (!config.s3.creds) {
|
|
27
|
-
if (!config.ow ||
|
|
28
|
-
!config.ow.namespace ||
|
|
29
|
-
!config.ow.auth ||
|
|
30
|
-
!config.s3.tvmUrl ||
|
|
31
|
-
!config.s3.credsCacheFile) {
|
|
32
|
-
throw new Error('Please check your .env file to ensure your credentials are correct. You can also use "aio app use" to load/refresh your credentials')
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
}
|
|
23
|
+
|
|
36
24
|
/// build files
|
|
37
25
|
const dist = config.web.distProd
|
|
38
26
|
if (!fs.existsSync(dist) ||
|
|
@@ -42,17 +30,16 @@ const deployWeb = async (config, log) => {
|
|
|
42
30
|
throw new Error(`missing files in ${dist}, maybe you forgot to build your UI ?`)
|
|
43
31
|
}
|
|
44
32
|
|
|
45
|
-
const creds = config
|
|
46
|
-
await getTvmCredentials(config.ow.namespace, config.ow.auth, config.s3.tvmUrl, config.s3.credsCacheFile)
|
|
33
|
+
const creds = await getS3Credentials(config)
|
|
47
34
|
|
|
48
35
|
const remoteStorage = new RemoteStorage(creds)
|
|
49
|
-
const exists = await remoteStorage.folderExists(config.s3.folder)
|
|
36
|
+
const exists = await remoteStorage.folderExists(config.s3.folder + '/')
|
|
50
37
|
|
|
51
38
|
if (exists) {
|
|
52
39
|
if (log) {
|
|
53
40
|
log('warning: an existing deployment will be overwritten')
|
|
54
41
|
}
|
|
55
|
-
await remoteStorage.emptyFolder(config.s3.folder)
|
|
42
|
+
await remoteStorage.emptyFolder(config.s3.folder + '/')
|
|
56
43
|
}
|
|
57
44
|
const _log = log ? (f) => log(`deploying ${path.relative(dist, f)}`) : null
|
|
58
45
|
await remoteStorage.uploadDir(dist, config.s3.folder, config.app, _log)
|
package/src/undeploy-web.js
CHANGED
|
@@ -11,14 +11,14 @@ governing permissions and limitations under the License.
|
|
|
11
11
|
*/
|
|
12
12
|
|
|
13
13
|
const RemoteStorage = require('../lib/remote-storage')
|
|
14
|
-
const
|
|
14
|
+
const getS3Credentials = require('../lib/getS3Creds')
|
|
15
15
|
|
|
16
16
|
const undeployWeb = async (config) => {
|
|
17
17
|
if (!config || !config.app || !config.app.hasFrontend) {
|
|
18
18
|
throw new Error('cannot undeploy web, app has no frontend or config is invalid')
|
|
19
19
|
}
|
|
20
20
|
|
|
21
|
-
const creds =
|
|
21
|
+
const creds = await getS3Credentials(config)
|
|
22
22
|
|
|
23
23
|
const remoteStorage = new RemoteStorage(creds)
|
|
24
24
|
|
|
@@ -11,35 +11,35 @@ governing permissions and limitations under the License.
|
|
|
11
11
|
*/
|
|
12
12
|
|
|
13
13
|
const mockBundle = jest.fn()
|
|
14
|
-
const mockMiddleware = jest.fn()
|
|
15
14
|
const mockConstructor = jest.fn()
|
|
16
15
|
const mockServe = jest.fn()
|
|
17
|
-
const mockStop = jest.fn()
|
|
18
16
|
|
|
19
17
|
// hack to expose constructor, somehow returning a jest.fn doesn't work as expected for commonjs (only es6)
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
18
|
+
class core {
|
|
19
|
+
constructor (...args) {
|
|
20
|
+
mockConstructor(...args)
|
|
21
|
+
global._bundler__arguments = args
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
run () {
|
|
25
|
+
mockBundle()
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
watch () {
|
|
29
|
+
mockServe()
|
|
28
30
|
}
|
|
29
31
|
}
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
Bundler.mockServe = mockServe
|
|
34
|
-
Bundler.mockStop = mockStop
|
|
32
|
+
core.mockBundle = mockBundle
|
|
33
|
+
core.mockConstructor = mockConstructor
|
|
34
|
+
core.mockServe = mockServe
|
|
35
35
|
|
|
36
36
|
// alias
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
Bundler.mockServe.mockReset()
|
|
42
|
-
Bundler.mockStop.mockReset()
|
|
37
|
+
core.mockReset = () => {
|
|
38
|
+
core.mockConstructor.mockReset()
|
|
39
|
+
core.mockBundle.mockReset()
|
|
40
|
+
core.mockServe.mockReset()
|
|
43
41
|
}
|
|
44
42
|
|
|
45
|
-
module.exports =
|
|
43
|
+
module.exports = {
|
|
44
|
+
default: core
|
|
45
|
+
}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright 2020 Adobe. All rights reserved.
|
|
3
|
+
This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
you may not use this file except in compliance with the License. You may obtain a copy
|
|
5
|
+
of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
6
|
+
|
|
7
|
+
Unless required by applicable law or agreed to in writing, software distributed under
|
|
8
|
+
the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
9
|
+
OF ANY KIND, either express or implied. See the License for the specific language
|
|
10
|
+
governing permissions and limitations under the License.
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
const getS3Credentials = require('../../lib/getS3Creds')
|
|
14
|
+
|
|
15
|
+
const fakeReturnedTvmCreds = { fake: 'tvmcreds' } // from __mocks__
|
|
16
|
+
const mockTVM = require('@adobe/aio-lib-core-tvm')
|
|
17
|
+
|
|
18
|
+
describe('getS3Credentials', () => {
|
|
19
|
+
beforeEach(() => {
|
|
20
|
+
mockTVM.init.mockClear()
|
|
21
|
+
})
|
|
22
|
+
|
|
23
|
+
test('throw when missing required args', async () => {
|
|
24
|
+
const expectedErrorMessage =
|
|
25
|
+
'Please check your .env file to ensure your credentials are correct.'
|
|
26
|
+
|
|
27
|
+
await expect(getS3Credentials({}))
|
|
28
|
+
.rejects.toThrow(expectedErrorMessage)
|
|
29
|
+
|
|
30
|
+
await expect(getS3Credentials({ ow: { namespace: 'ns' }, s3: {} }))
|
|
31
|
+
.rejects.toThrow(expectedErrorMessage)
|
|
32
|
+
|
|
33
|
+
await expect(getS3Credentials({ ow: { auth: 'auth' } }))
|
|
34
|
+
.rejects.toThrow(expectedErrorMessage)
|
|
35
|
+
})
|
|
36
|
+
|
|
37
|
+
test('returns s3.creds if defined', async () => {
|
|
38
|
+
const fakeCreds = { fake: 's3creds' }
|
|
39
|
+
await expect(getS3Credentials({ ow: { namespace: 'ns', auth: 'auth' }, s3: { creds: fakeCreds } }))
|
|
40
|
+
.resolves.toEqual(fakeCreds)
|
|
41
|
+
expect(mockTVM.init).not.toHaveBeenCalled()
|
|
42
|
+
})
|
|
43
|
+
|
|
44
|
+
test('gets credentials from tvm', async () => {
|
|
45
|
+
await expect(getS3Credentials({ ow: { namespace: 'ns', auth: 'auth' } }))
|
|
46
|
+
.resolves.toEqual(fakeReturnedTvmCreds)
|
|
47
|
+
expect(mockTVM.init).toBeCalledWith({
|
|
48
|
+
apiUrl: undefined,
|
|
49
|
+
cacheFile: undefined,
|
|
50
|
+
ow: { auth: 'auth', namespace: 'ns' }
|
|
51
|
+
})
|
|
52
|
+
})
|
|
53
|
+
|
|
54
|
+
test('gets credentials from tvm with custom tvmurl', async () => {
|
|
55
|
+
await expect(getS3Credentials({ ow: { namespace: 'ns', auth: 'auth' }, s3: { tvmUrl: 'custom' } }))
|
|
56
|
+
.resolves.toEqual(fakeReturnedTvmCreds)
|
|
57
|
+
expect(mockTVM.init).toBeCalledWith({
|
|
58
|
+
apiUrl: 'custom',
|
|
59
|
+
cacheFile: undefined,
|
|
60
|
+
ow: { auth: 'auth', namespace: 'ns' }
|
|
61
|
+
})
|
|
62
|
+
})
|
|
63
|
+
|
|
64
|
+
test('gets credentials from tvm with custom credsCacheFile', async () => {
|
|
65
|
+
await expect(getS3Credentials({ ow: { namespace: 'ns', auth: 'auth' }, s3: { credsCacheFile: 'custom' } }))
|
|
66
|
+
.resolves.toEqual(fakeReturnedTvmCreds)
|
|
67
|
+
expect(mockTVM.init).toBeCalledWith({
|
|
68
|
+
apiUrl: undefined,
|
|
69
|
+
cacheFile: 'custom',
|
|
70
|
+
ow: { auth: 'auth', namespace: 'ns' }
|
|
71
|
+
})
|
|
72
|
+
})
|
|
73
|
+
})
|
|
@@ -63,6 +63,18 @@ describe('build-web', () => {
|
|
|
63
63
|
global.addFakeFiles(vol, 'fakeDir', { 'index.html': '' })
|
|
64
64
|
fs.readdir.mockReturnValue(['output.html'])
|
|
65
65
|
await expect(buildWeb(config)).resolves.toEqual(['output.html'])
|
|
66
|
-
expect(global._bundler__arguments).toEqual([
|
|
66
|
+
expect(global._bundler__arguments).toEqual([
|
|
67
|
+
expect.objectContaining({
|
|
68
|
+
defaultConfig: expect.stringContaining(path.join('parcel', 'config-default', 'index.json')),
|
|
69
|
+
defaultTargetOptions: expect.objectContaining({
|
|
70
|
+
distDir: 'dist',
|
|
71
|
+
publicUrl: './'
|
|
72
|
+
}),
|
|
73
|
+
entries: path.join('fakeDir', 'index.html'),
|
|
74
|
+
logLevel: 'none',
|
|
75
|
+
shouldContentHash: true,
|
|
76
|
+
shouldDisableCache: true
|
|
77
|
+
})
|
|
78
|
+
])
|
|
67
79
|
})
|
|
68
80
|
})
|
package/test/src/bundle.test.js
CHANGED
|
@@ -14,6 +14,7 @@ const { vol } = global.mockFs()
|
|
|
14
14
|
const bundle = require('../../src/bundle')
|
|
15
15
|
const fs = require('fs-extra')
|
|
16
16
|
jest.mock('fs-extra')
|
|
17
|
+
const path = require('path')
|
|
17
18
|
|
|
18
19
|
describe('bundle', () => {
|
|
19
20
|
beforeEach(() => {
|
|
@@ -49,43 +50,59 @@ describe('bundle', () => {
|
|
|
49
50
|
|
|
50
51
|
test('check build options', async () => {
|
|
51
52
|
global.addFakeFiles(vol, 'fakeDir', { 'index.html': '' })
|
|
52
|
-
await expect(bundle('fakeDir/index.html', 'distProd')).resolves.toEqual(
|
|
53
|
-
expect.objectContaining({ bundler: expect.any(Object) }))
|
|
53
|
+
await expect(bundle('fakeDir/index.html', 'distProd')).resolves.toEqual(expect.any(Object))
|
|
54
54
|
expect(global._bundler__arguments).toEqual([
|
|
55
|
-
expect.stringContaining('fakeDir'),
|
|
56
55
|
expect.objectContaining({
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
56
|
+
defaultConfig: expect.stringContaining(path.join('parcel', 'config-default', 'index.json')),
|
|
57
|
+
defaultTargetOptions: expect.objectContaining({
|
|
58
|
+
distDir: 'distProd',
|
|
59
|
+
shouldOptimize: false
|
|
60
|
+
}),
|
|
61
|
+
entries: 'fakeDir/index.html',
|
|
62
|
+
logLevel: 'error',
|
|
63
|
+
shouldContentHash: true,
|
|
64
|
+
shouldDisableCache: false
|
|
62
65
|
})])
|
|
63
66
|
})
|
|
64
67
|
|
|
65
68
|
test('uses build options', async () => {
|
|
66
69
|
global.addFakeFiles(vol, 'fakeDir', { 'index.html': '' })
|
|
67
|
-
await expect(bundle('fakeDir/index.html', 'distProd', { contentHash: false, logLevel: 5 }))
|
|
68
|
-
.resolves.toEqual(expect.
|
|
70
|
+
await expect(bundle('fakeDir/index.html', 'distProd', { contentHash: false, logLevel: 5, shouldOptimize: false }))
|
|
71
|
+
.resolves.toEqual(expect.any(Object))
|
|
69
72
|
expect(global._bundler__arguments).toEqual([
|
|
70
|
-
expect.stringContaining('fakeDir'),
|
|
71
73
|
expect.objectContaining({
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
74
|
+
defaultConfig: expect.stringContaining(path.join('parcel', 'config-default', 'index.json')),
|
|
75
|
+
defaultTargetOptions: expect.objectContaining({
|
|
76
|
+
distDir: 'distProd',
|
|
77
|
+
shouldOptimize: false
|
|
78
|
+
}),
|
|
79
|
+
entries: 'fakeDir/index.html',
|
|
80
|
+
shouldContentHash: true,
|
|
81
|
+
shouldDisableCache: false
|
|
82
|
+
})])
|
|
83
|
+
})
|
|
84
|
+
|
|
85
|
+
test('uses build options - shouldOptimize', async () => {
|
|
86
|
+
global.addFakeFiles(vol, 'fakeDir', { 'index.html': '' })
|
|
87
|
+
await expect(bundle('fakeDir/index.html', 'distProd', { contentHash: false, logLevel: 5, shouldOptimize: true }))
|
|
88
|
+
.resolves.toEqual(expect.any(Object))
|
|
89
|
+
expect(global._bundler__arguments).toEqual([
|
|
90
|
+
expect.objectContaining({
|
|
91
|
+
defaultConfig: expect.stringContaining(path.join('parcel', 'config-default', 'index.json')),
|
|
92
|
+
defaultTargetOptions: expect.objectContaining({
|
|
93
|
+
distDir: 'distProd',
|
|
94
|
+
shouldOptimize: true
|
|
95
|
+
}),
|
|
96
|
+
entries: 'fakeDir/index.html',
|
|
97
|
+
shouldContentHash: true,
|
|
98
|
+
shouldDisableCache: false
|
|
77
99
|
})])
|
|
78
100
|
})
|
|
79
101
|
|
|
80
102
|
test('returns {bundle, cleanup}', async () => {
|
|
81
103
|
global.addFakeFiles(vol, 'fakeDir', { 'index.html': '' })
|
|
82
104
|
|
|
83
|
-
const
|
|
105
|
+
const bundler = await bundle('fakeDir/index.html', 'distProd', { contentHash: false, logLevel: 5 })
|
|
84
106
|
expect(bundler).toBeDefined()
|
|
85
|
-
expect(cleanup).toBeDefined()
|
|
86
|
-
expect(typeof cleanup).toBe('function')
|
|
87
|
-
bundler.stop = jest.fn()
|
|
88
|
-
cleanup()
|
|
89
|
-
expect(bundler.stop).toHaveBeenCalled()
|
|
90
107
|
})
|
|
91
108
|
})
|
|
@@ -14,30 +14,34 @@ const { vol } = global.mockFs()
|
|
|
14
14
|
const deployWeb = require('../../src/deploy-web')
|
|
15
15
|
const fs = require('fs-extra')
|
|
16
16
|
jest.mock('fs-extra')
|
|
17
|
-
const getTvmCredentials = require('../../lib/getTvmCreds')
|
|
18
|
-
jest.mock('../../lib/getTvmCreds')
|
|
19
17
|
|
|
18
|
+
jest.mock('../../lib/getS3Creds')
|
|
19
|
+
const getS3Credentials = require('../../lib/getS3Creds')
|
|
20
|
+
getS3Credentials.mockResolvedValue('fakecreds')
|
|
21
|
+
|
|
22
|
+
const mockRemoteStorageInstance = {
|
|
23
|
+
emptyFolder: jest.fn(),
|
|
24
|
+
folderExists: jest.fn(),
|
|
25
|
+
uploadDir: jest.fn()
|
|
26
|
+
}
|
|
20
27
|
const RemoteStorage = require('../../lib/remote-storage')
|
|
21
28
|
jest.mock('../../lib/remote-storage', () => {
|
|
22
29
|
return jest.fn().mockImplementation(() => {
|
|
23
|
-
return
|
|
24
|
-
emptyFolder: jest.fn(),
|
|
25
|
-
folderExists: jest.fn().mockResolvedValue(true),
|
|
26
|
-
uploadDir: jest.fn().mockImplementation((dist, folder, app, logFunc) => {
|
|
27
|
-
logFunc && logFunc('boo')
|
|
28
|
-
})
|
|
29
|
-
}
|
|
30
|
+
return mockRemoteStorageInstance
|
|
30
31
|
})
|
|
31
32
|
})
|
|
32
33
|
|
|
33
34
|
describe('deploy-web', () => {
|
|
34
|
-
const errString = 'Please check your .env file to ensure your credentials are correct. You can also use "aio app use" to load/refresh your credentials'
|
|
35
35
|
beforeEach(() => {
|
|
36
|
-
// restores all spies
|
|
37
36
|
RemoteStorage.mockClear()
|
|
38
|
-
|
|
37
|
+
mockRemoteStorageInstance.emptyFolder.mockReset()
|
|
38
|
+
mockRemoteStorageInstance.folderExists.mockReset()
|
|
39
|
+
mockRemoteStorageInstance.uploadDir.mockReset()
|
|
40
|
+
getS3Credentials.mockClear()
|
|
41
|
+
|
|
39
42
|
global.cleanFs(vol)
|
|
40
43
|
})
|
|
44
|
+
|
|
41
45
|
test('throws if config does not have an app, or frontEnd', async () => {
|
|
42
46
|
await expect(deployWeb()).rejects.toThrow('cannot deploy web')
|
|
43
47
|
await expect(deployWeb({ app: 'nothing-here' })).rejects.toThrow('cannot deploy web')
|
|
@@ -94,46 +98,46 @@ describe('deploy-web', () => {
|
|
|
94
98
|
await expect(deployWeb(config)).rejects.toThrow('missing files in dist')
|
|
95
99
|
})
|
|
96
100
|
|
|
97
|
-
test('
|
|
101
|
+
test('uploads files', async () => {
|
|
98
102
|
const config = {
|
|
99
|
-
|
|
103
|
+
ow: {
|
|
104
|
+
namespace: 'ns',
|
|
105
|
+
auth: 'password'
|
|
106
|
+
},
|
|
107
|
+
s3: {
|
|
108
|
+
credsCacheFile: 'file',
|
|
109
|
+
tvmUrl: 'url',
|
|
110
|
+
folder: 'somefolder'
|
|
111
|
+
},
|
|
100
112
|
app: {
|
|
101
|
-
hasFrontend: true
|
|
113
|
+
hasFrontend: true,
|
|
114
|
+
hostname: 'host'
|
|
102
115
|
},
|
|
103
116
|
web: {
|
|
104
117
|
distProd: 'dist'
|
|
105
118
|
}
|
|
106
119
|
}
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
await expect(deployWeb(config)).
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
await expect(deployWeb(config)).rejects.toThrow(errString)
|
|
117
|
-
|
|
118
|
-
config.ow.auth = '_'
|
|
119
|
-
await expect(deployWeb(config)).rejects.toThrow(errString)
|
|
120
|
-
|
|
121
|
-
config.s3.tvmUrl = 'asd'
|
|
122
|
-
await expect(deployWeb(config)).rejects.toThrow(errString)
|
|
123
|
-
|
|
124
|
-
config.s3.credsCacheFile = 'asd'
|
|
125
|
-
await expect(deployWeb(config)).rejects.toThrow('missing files')
|
|
120
|
+
fs.existsSync.mockReturnValue(true)
|
|
121
|
+
fs.lstatSync.mockReturnValue({ isDirectory: () => true })
|
|
122
|
+
fs.readdirSync.mockReturnValue({ length: 1 })
|
|
123
|
+
await expect(deployWeb(config)).resolves.toEqual('https://ns.host/index.html')
|
|
124
|
+
expect(getS3Credentials).toHaveBeenCalledWith(config)
|
|
125
|
+
expect(RemoteStorage).toHaveBeenCalledWith('fakecreds')
|
|
126
|
+
expect(mockRemoteStorageInstance.uploadDir).toHaveBeenCalledWith('dist', 'somefolder', config.app, null)
|
|
127
|
+
expect(mockRemoteStorageInstance.emptyFolder).not.toHaveBeenCalled()
|
|
128
|
+
expect(mockRemoteStorageInstance.folderExists).toHaveBeenCalledWith('somefolder/')
|
|
126
129
|
})
|
|
127
130
|
|
|
128
|
-
test('
|
|
131
|
+
test('uploads files with log func', async () => {
|
|
129
132
|
const config = {
|
|
130
133
|
ow: {
|
|
131
134
|
namespace: 'ns',
|
|
132
|
-
auth: '
|
|
135
|
+
auth: 'password'
|
|
133
136
|
},
|
|
134
137
|
s3: {
|
|
135
|
-
|
|
136
|
-
|
|
138
|
+
credsCacheFile: 'file',
|
|
139
|
+
tvmUrl: 'url',
|
|
140
|
+
folder: 'somefolder'
|
|
137
141
|
},
|
|
138
142
|
app: {
|
|
139
143
|
hasFrontend: true,
|
|
@@ -146,20 +150,26 @@ describe('deploy-web', () => {
|
|
|
146
150
|
fs.existsSync.mockReturnValue(true)
|
|
147
151
|
fs.lstatSync.mockReturnValue({ isDirectory: () => true })
|
|
148
152
|
fs.readdirSync.mockReturnValue({ length: 1 })
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
153
|
+
const mockLogger = jest.fn()
|
|
154
|
+
// for func coverage
|
|
155
|
+
mockRemoteStorageInstance.uploadDir.mockImplementation((a, b, c, func) => func('somefile'))
|
|
156
|
+
await expect(deployWeb(config, mockLogger)).resolves.toEqual('https://ns.host/index.html')
|
|
157
|
+
expect(getS3Credentials).toHaveBeenCalledWith(config)
|
|
158
|
+
expect(RemoteStorage).toHaveBeenCalledWith('fakecreds')
|
|
159
|
+
expect(mockRemoteStorageInstance.uploadDir).toHaveBeenCalledWith('dist', 'somefolder', config.app, expect.any(Function))
|
|
160
|
+
expect(mockRemoteStorageInstance.emptyFolder).not.toHaveBeenCalled()
|
|
161
|
+
expect(mockRemoteStorageInstance.folderExists).toHaveBeenCalledWith('somefolder/')
|
|
152
162
|
})
|
|
153
163
|
|
|
154
|
-
test('
|
|
164
|
+
test('overwrites remote files', async () => {
|
|
155
165
|
const config = {
|
|
156
166
|
ow: {
|
|
157
167
|
namespace: 'ns',
|
|
158
168
|
auth: 'password'
|
|
159
169
|
},
|
|
160
170
|
s3: {
|
|
161
|
-
|
|
162
|
-
|
|
171
|
+
creds: 'somecreds',
|
|
172
|
+
folder: 'somefolder'
|
|
163
173
|
},
|
|
164
174
|
app: {
|
|
165
175
|
hasFrontend: true,
|
|
@@ -171,15 +181,53 @@ describe('deploy-web', () => {
|
|
|
171
181
|
}
|
|
172
182
|
fs.existsSync.mockReturnValue(true)
|
|
173
183
|
fs.lstatSync.mockReturnValue({ isDirectory: () => true })
|
|
174
|
-
fs.readdirSync.mockReturnValue({ length: 1 })
|
|
175
184
|
const mockLogger = jest.fn()
|
|
185
|
+
fs.readdirSync.mockReturnValue({ length: 1 })
|
|
186
|
+
|
|
187
|
+
mockRemoteStorageInstance.folderExists.mockResolvedValue(true)
|
|
188
|
+
|
|
176
189
|
await expect(deployWeb(config, mockLogger)).resolves.toEqual('https://ns.host/index.html')
|
|
177
|
-
expect(
|
|
178
|
-
expect(
|
|
179
|
-
expect(RemoteStorage).
|
|
190
|
+
expect(getS3Credentials).toHaveBeenCalledWith(config)
|
|
191
|
+
expect(mockLogger).toHaveBeenCalledWith('warning: an existing deployment will be overwritten')
|
|
192
|
+
expect(RemoteStorage).toHaveBeenCalledWith('fakecreds')
|
|
193
|
+
expect(mockRemoteStorageInstance.folderExists).toHaveBeenCalledWith('somefolder/')
|
|
194
|
+
expect(mockRemoteStorageInstance.uploadDir).toHaveBeenCalledWith('dist', 'somefolder', config.app, expect.any(Function))
|
|
195
|
+
// empty dir!
|
|
196
|
+
expect(mockRemoteStorageInstance.emptyFolder).toHaveBeenCalledWith('somefolder/')
|
|
197
|
+
})
|
|
198
|
+
|
|
199
|
+
test('overwrites remote files no log func', async () => {
|
|
200
|
+
const config = {
|
|
201
|
+
ow: {
|
|
202
|
+
namespace: 'ns',
|
|
203
|
+
auth: 'password'
|
|
204
|
+
},
|
|
205
|
+
s3: {
|
|
206
|
+
folder: 'somefolder'
|
|
207
|
+
},
|
|
208
|
+
app: {
|
|
209
|
+
hasFrontend: true,
|
|
210
|
+
hostname: 'host'
|
|
211
|
+
},
|
|
212
|
+
web: {
|
|
213
|
+
distProd: 'dist'
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
fs.existsSync.mockReturnValue(true)
|
|
217
|
+
fs.lstatSync.mockReturnValue({ isDirectory: () => true })
|
|
218
|
+
fs.readdirSync.mockReturnValue({ length: 1 })
|
|
219
|
+
|
|
220
|
+
mockRemoteStorageInstance.folderExists.mockResolvedValue(true)
|
|
221
|
+
|
|
222
|
+
await expect(deployWeb(config)).resolves.toEqual('https://ns.host/index.html')
|
|
223
|
+
expect(getS3Credentials).toHaveBeenCalledWith(config)
|
|
224
|
+
expect(mockRemoteStorageInstance.folderExists).toHaveBeenCalledWith('somefolder/')
|
|
225
|
+
expect(mockRemoteStorageInstance.uploadDir).toHaveBeenCalledWith('dist', 'somefolder', config.app, null)
|
|
226
|
+
// empty dir!
|
|
227
|
+
expect(mockRemoteStorageInstance.emptyFolder).toHaveBeenCalledWith('somefolder/')
|
|
180
228
|
})
|
|
181
229
|
|
|
182
|
-
test('
|
|
230
|
+
test('calls to s3 should use ending slash', async () => {
|
|
183
231
|
const config = {
|
|
184
232
|
ow: {
|
|
185
233
|
namespace: 'ns',
|
|
@@ -187,7 +235,8 @@ describe('deploy-web', () => {
|
|
|
187
235
|
},
|
|
188
236
|
s3: {
|
|
189
237
|
credsCacheFile: 'file',
|
|
190
|
-
tvmUrl: 'url'
|
|
238
|
+
tvmUrl: 'url',
|
|
239
|
+
folder: 'nsfolder'
|
|
191
240
|
},
|
|
192
241
|
app: {
|
|
193
242
|
hasFrontend: true,
|
|
@@ -197,10 +246,12 @@ describe('deploy-web', () => {
|
|
|
197
246
|
distProd: 'dist'
|
|
198
247
|
}
|
|
199
248
|
}
|
|
249
|
+
const emptyFolder = jest.fn()
|
|
250
|
+
const folderExists = jest.fn(() => true)
|
|
200
251
|
RemoteStorage.mockImplementation(() => {
|
|
201
252
|
return {
|
|
202
|
-
emptyFolder
|
|
203
|
-
folderExists
|
|
253
|
+
emptyFolder,
|
|
254
|
+
folderExists,
|
|
204
255
|
uploadDir: jest.fn()
|
|
205
256
|
}
|
|
206
257
|
})
|
|
@@ -209,10 +260,9 @@ describe('deploy-web', () => {
|
|
|
209
260
|
const mockLogger = jest.fn()
|
|
210
261
|
fs.readdirSync.mockReturnValue({ length: 1 })
|
|
211
262
|
await expect(deployWeb(config, mockLogger)).resolves.toEqual('https://ns.host/index.html')
|
|
212
|
-
expect(
|
|
213
|
-
expect(getTvmCredentials).toHaveBeenCalled()
|
|
263
|
+
expect(getS3Credentials).toHaveBeenCalled()
|
|
214
264
|
expect(RemoteStorage).toHaveBeenCalledTimes(1)
|
|
265
|
+
expect(folderExists).toHaveBeenLastCalledWith('nsfolder/')
|
|
266
|
+
expect(emptyFolder).toHaveBeenLastCalledWith('nsfolder/')
|
|
215
267
|
})
|
|
216
|
-
|
|
217
|
-
// if !tvm creds, then we require config.ow.namespace, config.ow.auth, config.s3.tvmUrl, config.s3.credsCacheFile
|
|
218
268
|
})
|
|
@@ -11,23 +11,28 @@ governing permissions and limitations under the License.
|
|
|
11
11
|
*/
|
|
12
12
|
|
|
13
13
|
const undeployWeb = require('../../src/undeploy-web')
|
|
14
|
-
|
|
15
|
-
jest.mock('../../lib/
|
|
14
|
+
|
|
15
|
+
jest.mock('../../lib/getS3Creds')
|
|
16
|
+
const getS3Credentials = require('../../lib/getS3Creds')
|
|
17
|
+
getS3Credentials.mockResolvedValue('fakecreds')
|
|
18
|
+
|
|
19
|
+
const mockRemoteStorageInstance = {
|
|
20
|
+
emptyFolder: jest.fn(),
|
|
21
|
+
folderExists: jest.fn()
|
|
22
|
+
}
|
|
16
23
|
const RemoteStorage = require('../../lib/remote-storage')
|
|
17
24
|
jest.mock('../../lib/remote-storage', () => {
|
|
18
25
|
return jest.fn().mockImplementation(() => {
|
|
19
|
-
return
|
|
20
|
-
emptyFolder: jest.fn(),
|
|
21
|
-
folderExists: jest.fn().mockResolvedValue(true),
|
|
22
|
-
uploadDir: jest.fn()
|
|
23
|
-
}
|
|
26
|
+
return mockRemoteStorageInstance
|
|
24
27
|
})
|
|
25
28
|
})
|
|
26
29
|
|
|
27
30
|
describe('undeploy-web', () => {
|
|
28
31
|
beforeEach(() => {
|
|
29
32
|
RemoteStorage.mockClear()
|
|
30
|
-
|
|
33
|
+
mockRemoteStorageInstance.emptyFolder.mockReset()
|
|
34
|
+
mockRemoteStorageInstance.folderExists.mockReset()
|
|
35
|
+
getS3Credentials.mockClear()
|
|
31
36
|
})
|
|
32
37
|
|
|
33
38
|
test('throws if config does not have an app, or frontEnd', async () => {
|
|
@@ -36,20 +41,31 @@ describe('undeploy-web', () => {
|
|
|
36
41
|
await expect(undeployWeb({ app: { hasFrontEnd: false } })).rejects.toThrow('cannot undeploy web')
|
|
37
42
|
})
|
|
38
43
|
|
|
39
|
-
test('
|
|
44
|
+
test('calls getS3Credentials and empties folder', async () => {
|
|
40
45
|
const config = {
|
|
46
|
+
ow: {
|
|
47
|
+
namespace: 'ns',
|
|
48
|
+
auth: 'password'
|
|
49
|
+
},
|
|
41
50
|
s3: {
|
|
42
|
-
creds: '
|
|
51
|
+
creds: 'fakes3creds',
|
|
52
|
+
tvmUrl: 'url',
|
|
53
|
+
folder: 'somefolder'
|
|
43
54
|
},
|
|
44
55
|
app: {
|
|
45
|
-
hasFrontend: true
|
|
56
|
+
hasFrontend: true,
|
|
57
|
+
hostname: 'host'
|
|
46
58
|
},
|
|
47
59
|
web: {
|
|
48
60
|
distProd: 'dist'
|
|
49
61
|
}
|
|
50
62
|
}
|
|
51
|
-
|
|
52
|
-
|
|
63
|
+
mockRemoteStorageInstance.folderExists.mockResolvedValue(true)
|
|
64
|
+
await undeployWeb(config)
|
|
65
|
+
expect(getS3Credentials).toHaveBeenCalledWith(config)
|
|
66
|
+
expect(RemoteStorage).toHaveBeenCalledWith('fakecreds')
|
|
67
|
+
expect(mockRemoteStorageInstance.folderExists).toHaveBeenCalledWith('somefolder')
|
|
68
|
+
expect(mockRemoteStorageInstance.emptyFolder).toHaveBeenCalledWith('somefolder')
|
|
53
69
|
})
|
|
54
70
|
|
|
55
71
|
test('throws if remoteStorage folder does not exist', async () => {
|
|
@@ -60,7 +76,8 @@ describe('undeploy-web', () => {
|
|
|
60
76
|
},
|
|
61
77
|
s3: {
|
|
62
78
|
credsCacheFile: 'file',
|
|
63
|
-
tvmUrl: 'url'
|
|
79
|
+
tvmUrl: 'url',
|
|
80
|
+
folder: 'somefolder'
|
|
64
81
|
},
|
|
65
82
|
app: {
|
|
66
83
|
hasFrontend: true
|
|
@@ -69,14 +86,10 @@ describe('undeploy-web', () => {
|
|
|
69
86
|
distProd: 'dist'
|
|
70
87
|
}
|
|
71
88
|
}
|
|
72
|
-
RemoteStorage.mockImplementation(() => {
|
|
73
|
-
return {
|
|
74
|
-
emptyFolder: jest.fn(),
|
|
75
|
-
folderExists: jest.fn().mockResolvedValue(false),
|
|
76
|
-
uploadDir: jest.fn()
|
|
77
|
-
}
|
|
78
|
-
})
|
|
79
89
|
await expect(undeployWeb(config)).rejects.toThrow('cannot undeploy static files')
|
|
80
|
-
expect(
|
|
90
|
+
expect(getS3Credentials).toHaveBeenCalledWith(config)
|
|
91
|
+
expect(RemoteStorage).toHaveBeenCalledWith('fakecreds')
|
|
92
|
+
expect(mockRemoteStorageInstance.folderExists).toHaveBeenCalledWith('somefolder')
|
|
93
|
+
expect(mockRemoteStorageInstance.emptyFolder).not.toHaveBeenCalled()
|
|
81
94
|
})
|
|
82
95
|
})
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
Copyright 2020 Adobe. All rights reserved.
|
|
3
|
-
This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
4
|
-
you may not use this file except in compliance with the License. You may obtain a copy
|
|
5
|
-
of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
6
|
-
|
|
7
|
-
Unless required by applicable law or agreed to in writing, software distributed under
|
|
8
|
-
the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
9
|
-
OF ANY KIND, either express or implied. See the License for the specific language
|
|
10
|
-
governing permissions and limitations under the License.
|
|
11
|
-
*/
|
|
12
|
-
|
|
13
|
-
const getTvmCredentials = require('../../lib/getTvmCreds')
|
|
14
|
-
|
|
15
|
-
describe('getTvmCredentials', () => {
|
|
16
|
-
beforeEach(() => {
|
|
17
|
-
// restores all spies
|
|
18
|
-
jest.restoreAllMocks()
|
|
19
|
-
})
|
|
20
|
-
|
|
21
|
-
test('throw when missing required args', async () => {
|
|
22
|
-
// const creds = getTvmCredentials()
|
|
23
|
-
await expect(getTvmCredentials())
|
|
24
|
-
.rejects.toThrow('Missing required argument')
|
|
25
|
-
|
|
26
|
-
await expect(getTvmCredentials('ns'))
|
|
27
|
-
.rejects.toThrow('Missing required argument')
|
|
28
|
-
|
|
29
|
-
await expect(getTvmCredentials('ns', 'auth'))
|
|
30
|
-
.rejects.toThrow('Missing required argument')
|
|
31
|
-
|
|
32
|
-
await expect(getTvmCredentials('ns', 'auth', 'apiUrl'))
|
|
33
|
-
.rejects.toThrow('Missing required argument')
|
|
34
|
-
|
|
35
|
-
const creds = await getTvmCredentials('ns', 'auth', 'http://apiUrl', 'cacheFile')
|
|
36
|
-
|
|
37
|
-
expect(creds).toBe('getAwsS3Credentials')
|
|
38
|
-
})
|
|
39
|
-
})
|