JasonEtco / build-and-tag-action

📦🔖 A GitHub Action for publishing JavaScript Actions
MIT License
92 stars 38 forks source link

`index.ts` test state leaks across tests #43

Open filmaj opened 1 year ago

filmaj commented 1 year ago

Was trying to add a feature and was writing tests and saw some very weird behaviour on node v20.2.0.

In /tests/index.ts.ts, in the beforeEach, if you add this console.log line at the end of the setup function:

  beforeEach(() => {
    nock.cleanAll()
    tools = generateToolkit()
    delete process.env.INPUT_SETUP
    delete process.env.INPUT_TAG_NAME
    console.log(tools.context.payload)
  })

... you can see that the context.payload state that is modified in certain tests in index.test.ts (like setting draft or prelease) leaks across tests. Here's the output from npm test (see last two logs):

  ● Console

    console.log
      { release: { draft: false, prerelease: false, tag_name: 'v1.0.0' } }

      at Object.<anonymous> (tests/index.test.ts:14:13)

    console.log
      { release: { draft: false, prerelease: false, tag_name: 'v1.0.0' } }

      at Object.<anonymous> (tests/index.test.ts:14:13)

    console.log
      { release: { draft: false, prerelease: false, tag_name: 'v1.0.0' } }

      at Object.<anonymous> (tests/index.test.ts:14:13)

    console.log
      { release: { draft: true, prerelease: false, tag_name: 'v1.0.0' } }

      at Object.<anonymous> (tests/index.test.ts:14:13)

    console.log
      { release: { draft: true, prerelease: true, tag_name: 'v1.0.0' } }

      at Object.<anonymous> (tests/index.test.ts:14:13)