Closed lakidd closed 4 years ago
Sure!
For the backend, npm install
should be sufficient to grab all dependencies.
sls deploy
should take care of deployment. Be sure to check the profile
variable in serverless.yml
. You might not need it (in fact, it shouldn't be in the repository).
Can you send me some details about the failing unit tests?
Thanks, as I noted I'm very green to all this so could be doing something very silly... I fixed the profile variable
Here's the output of sls deploy
[lachlak:...home-energy-monitor/src-aws]$ sls deploy (master✱)
Serverless: Bundling with Webpack...
Time: 529ms
Built at: 02/17/2020 8:12:31 PM
Asset Size Chunks Chunk Names
functions/cron-rotate-daily.js 5.63 KiB 0 [emitted] functions/cron-rotate-daily
Entrypoint functions/cron-rotate-daily = functions/cron-rotate-daily.js
[0] ./core/aws-connections.js 155 bytes {0} [built]
[1] ./core/config.js 177 bytes {0} [built]
[2] ./functions/cron-rotate-daily.js 3.35 KiB {0} [built]
[3] external "aws-sdk" 42 bytes {0} [built]
[4] ./core/helpers.js 4.71 KiB {0} [built]
[5] external "util" 42 bytes {0} [built]
[6] external "zlib" 42 bytes {0} [built]
[7] ./core/helpers/CalculateKwh.js 961 bytes {0} [built]
[8] ./core/helpers/IsNightTarif.js 492 bytes {0} [built]
Time: 636ms
Built at: 02/17/2020 8:12:31 PM
Asset Size Chunks Chunk Names
functions/graphql/graphql.js 8.56 KiB 0 [emitted] functions/graphql/graphql
Entrypoint functions/graphql/graphql = functions/graphql/graphql.js
[0] ./core/config.js 177 bytes {0} [built]
[1] ./core/aws-connections.js 155 bytes {0} [built]
[2] ./core/helpers.js 4.71 KiB {0} [built]
[3] ./functions/graphql/graphql.js 1.25 KiB {0} [built]
[4] external "graphql/index" 42 bytes {0} [built]
[5] ./functions/graphql/resolvers/realtime.js 967 bytes {0} [built]
[6] external "aws-sdk" 42 bytes {0} [built]
[7] external "util" 42 bytes {0} [built]
[8] external "zlib" 42 bytes {0} [built]
[9] ./functions/graphql/resolvers/usageData.js 543 bytes {0} [built]
[10] ./functions/graphql/resolvers/stats.js 1.38 KiB {0} [built]
[11] ./node_modules/graphql-fields/build/index.js 4.98 KiB {0} [built]
[12] ./core/helpers/CalculateKwh.js 961 bytes {0} [built]
[13] ./core/helpers/IsNightTarif.js 492 bytes {0} [built]
[14] external "jStat" 42 bytes {0} [built]
Serverless: Package lock found - Using locked versions
Serverless: Packing external modules: graphql@^14.6.0, jStat@^1.8.6
Running command: npm run test
> src-aws@1.0.0 test /Users/lachlak/interesting_projects/home-energy-monitor/src-aws
> mocha "tests" "./core/helpers/*.test.js"
Warning: Cannot find any files matching pattern "tests"
Calculate kWh
1) should return 1 when consuming 1000W for 1 hour
2) should return 0.5 when consuming 1000W for 30min
IsNightTarif
3) should return true for night hours
4) should return false for day hours
✓ should return true for weekends
✓ should also work when we pass integers instead of date objects
2 passing (8ms)
4 failing
1) Calculate kWh
should return 1 when consuming 1000W for 1 hour:
AssertionError [ERR_ASSERTION]: 0 == 1
+ expected - actual
-0
+1
at Context.<anonymous> (core/helpers/CalculateKwh.test.js:14:15)
at processImmediate (internal/timers.js:456:21)
2) Calculate kWh
should return 0.5 when consuming 1000W for 30min:
AssertionError [ERR_ASSERTION]: 0 == 0.5
+ expected - actual
-0
+0.5
at Context.<anonymous> (core/helpers/CalculateKwh.test.js:26:15)
at processImmediate (internal/timers.js:456:21)
3) IsNightTarif
should return true for night hours:
AssertionError [ERR_ASSERTION]: false == true
+ expected - actual
-false
+true
at Context.<anonymous> (core/helpers/IsNightTarif.test.js:8:15)
at processImmediate (internal/timers.js:456:21)
4) IsNightTarif
should return false for day hours:
AssertionError [ERR_ASSERTION]: true == false
+ expected - actual
-true
+false
at Context.<anonymous> (core/helpers/IsNightTarif.test.js:13:16)
at processImmediate (internal/timers.js:456:21)
npm ERR! code ELIFECYCLE
npm ERR! errno 4
npm ERR! src-aws@1.0.0 test: `mocha "tests" "./core/helpers/*.test.js"`
npm ERR! Exit status 4
npm ERR!
npm ERR! Failed at the src-aws@1.0.0 test script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! /Users/lachlak/.npm/_logs/2020-02-17T09_12_42_750Z-debug.log
Error --------------------------------------------------
Error: Command failed: npm run test
at checkExecSyncError (child_process.js:621:11)
at Object.execSync (child_process.js:657:15)
at childProcess.execSync (pkg/prelude/bootstrap.js:1448:30)
at Scriptable.runCommand (/Users/lachlak/interesting_projects/home-energy-monitor/src-aws/node_modules/serverless-scriptable-plugin/index.js:48:12)
at /Users/lachlak/interesting_projects/home-energy-monitor/src-aws/node_modules/serverless-scriptable-plugin/index.js:41:21
at tryCatcher (/Users/lachlak/interesting_projects/home-energy-monitor/src-aws/node_modules/bluebird/js/release/util.js:16:23)
at Object.gotValue (/Users/lachlak/interesting_projects/home-energy-monitor/src-aws/node_modules/bluebird/js/release/reduce.js:166:18)
at Object.gotAccum (/Users/lachlak/interesting_projects/home-energy-monitor/src-aws/node_modules/bluebird/js/release/reduce.js:155:25)
at Object.tryCatcher (/Users/lachlak/interesting_projects/home-energy-monitor/src-aws/node_modules/bluebird/js/release/util.js:16:23)
at Promise._settlePromiseFromHandler (/Users/lachlak/interesting_projects/home-energy-monitor/src-aws/node_modules/bluebird/js/release/promise.js:547:31)
at Promise._settlePromise (/Users/lachlak/interesting_projects/home-energy-monitor/src-aws/node_modules/bluebird/js/release/promise.js:604:18)
at Promise._settlePromiseCtx (/Users/lachlak/interesting_projects/home-energy-monitor/src-aws/node_modules/bluebird/js/release/promise.js:641:10)
at _drainQueueStep (/Users/lachlak/interesting_projects/home-energy-monitor/src-aws/node_modules/bluebird/js/release/async.js:97:12)
at _drainQueue (/Users/lachlak/interesting_projects/home-energy-monitor/src-aws/node_modules/bluebird/js/release/async.js:86:9)
at Async._drainQueues (/Users/lachlak/interesting_projects/home-energy-monitor/src-aws/node_modules/bluebird/js/release/async.js:102:5)
at Immediate.Async.drainQueues [as _onImmediate] (/Users/lachlak/interesting_projects/home-energy-monitor/src-aws/node_modules/bluebird/js/release/async.js:15:14)
at processImmediate (internal/timers.js:439:21)
at process.topLevelDomainCallback (domain.js:130:23)
For debugging logs, run again after setting the "SLS_DEBUG=*" environment variable.
Get Support --------------------------------------------
Docs: docs.serverless.com
Bugs: github.com/serverless/serverless/issues
Issues: forum.serverless.com
Your Environment Information ---------------------------
Operating System: darwin
Node Version: 12.13.1
Framework Version: 1.63.0 (standalone)
Plugin Version: 3.3.0
SDK Version: 2.3.0
Components Core Version: 1.1.2
Components CLI Version: 1.4.0
Strange that these tests fail. They are basic maths. What version of node are you running?
To test, you can try disabling the unit tests before deploying. Remove the before
scriptHook in serverless.yml
(https://github.com/Savjee/home-energy-monitor/blob/master/src-aws/serverless.yml#L216)
[lachlak:~]$ node -v v13.8.0
Yeah thats what i thought...very strange..
I'll try it w/o the tests...thanks
Closing this issue for now. Feel free to re-open when necessary.
Hi I see that you have deployment as a TODO, but is there a 100 words or less version ? I've blundered my way through i think... Installing serverless cli tools Installing the dependencies (webpack etc) But when I do a serverless deploy, the unit tests fail.. Now, I'm a complete beginner when it comes to AWS and serverless tech, I come from the esp32 side of the house :) Thanks