You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Important takeaway: wrap your lock action scripts like this:
// my-script.jsimportcorefrom"@actions/core";import{Octokit}from"@octokit/core";if(process.env.GITHUB_ACTIONS&&process.env.NODE_ENV!=="test"){constoctokit=newOctokit({auth: process.env.GITHUB_TOKEN,});run(process.env,octokit,core);}exportasyncfunctionrun(env,octokit,core){// use `env` instead of `process.env`core.info("I did a thing")}
And then your test file can look like this
// test/my-script-test.jsimport{run}from"../my-script.js";// mock environment variablesconstmockEnv={};// mock octokitconstmockOctokit={};// mock coreconstoutputLogs=[];constmockCore={info(message){outputLogs.push(message);}};// run actionawaitrun(mockEnv,mockOctokit,mockCore);// assertionsdeepEqual(outputLogs,["I did a thing",]);
That way, you can run your tests as part of your CI using GitHub actions, but make sure to set NODE_END to "test"
💁🏻 Automating gr2m/helpdesk: Creating tests for actions for faster iteration
📅 Thursday, August 19, 2021
🕐 10:00am Pacific Time
🎙️ no guests
📍 https://www.twitch.tv/gregorcodes
🏷️ testing
Subscribe to this issues to get a notification before the show begins and a summary after the show concludes.
Creating tests for actions for faster iteration
Creating tests for local actions is a huge time saver. It enables quick iteration and avoid regressions once problems occur.
Outline
I will create tests for the existing actions in this repository
TODOs
Before the show
When show begins
After the show
(https://twitter.com/gr2m)
Recording
Shownotes
get-schow-schedules.js
. The final test file:test/get-show-schedules-test.js)
mockdate
for mocking theDate
API, so that tests won't start failing next week :)uvu
as a simple test runner, so that I can run all tests withnpm test
.github/workflows/test.yml
Important takeaway: wrap your lock action scripts like this:
And then your test file can look like this
That way, you can run your tests as part of your CI using GitHub actions, but make sure to set
NODE_END
to"test"
The text was updated successfully, but these errors were encountered: