diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 3433aaf..474fe79 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -1,5 +1,8 @@ name: 'Test the action' -on: [pull_request] +on: + pull_request: + branches: + - master jobs: test-json: @@ -502,21 +505,24 @@ jobs: EXPECTED_TAG: 'v1.5.0' with: github-token: ${{ secrets.github_token }} - version-file: 'test-file.json, test-file.toml, test-file.yaml' + version-file: 'test-file.json, test-file-2.json, test-file.toml, test-file.yaml' - name: Show files run: | - echo "$( { return new Promise((resolve) => { @@ -27,5 +27,4 @@ module.exports = new (class Git extends BaseVersioning { }) } -}) - +} diff --git a/src/version/index.js b/src/version/index.js index 6f9a80b..f3520e4 100644 --- a/src/version/index.js +++ b/src/version/index.js @@ -6,17 +6,17 @@ const Toml = require('./toml') module.exports = (fileExtension) => { switch (fileExtension.toLowerCase()) { case 'json': - return Json + return new Json() case 'yaml': case 'yml': - return Yaml + return new Yaml() case 'toml': - return Toml + return new Toml() case 'git': - return Git + return new Git() default: return null diff --git a/src/version/json.js b/src/version/json.js index 88f34f0..dff17a5 100644 --- a/src/version/json.js +++ b/src/version/json.js @@ -4,7 +4,7 @@ const objectPath = require('object-path') const BaseVersioning = require('./base') const bumpVersion = require('../helpers/bumpVersion') -module.exports = new (class Json extends BaseVersioning { +module.exports = class Json extends BaseVersioning { /** * Bumps the version in the package.json @@ -49,5 +49,5 @@ module.exports = new (class Json extends BaseVersioning { ) } -}) +} diff --git a/src/version/toml.js b/src/version/toml.js index ce08a66..813b69c 100644 --- a/src/version/toml.js +++ b/src/version/toml.js @@ -5,7 +5,7 @@ const toml = require('@iarna/toml') const BaseVersioning = require('./base') const bumpVersion = require('../helpers/bumpVersion') -module.exports = new (class Toml extends BaseVersioning { +module.exports = class Toml extends BaseVersioning { /** * Bumps the version in the package.json @@ -46,5 +46,5 @@ module.exports = new (class Toml extends BaseVersioning { } } -}) +} diff --git a/src/version/yaml.js b/src/version/yaml.js index be9b72b..b82acac 100644 --- a/src/version/yaml.js +++ b/src/version/yaml.js @@ -5,7 +5,7 @@ const yaml = require('yaml') const BaseVersioning = require('./base') const bumpVersion = require('../helpers/bumpVersion') -module.exports = new (class Yaml extends BaseVersioning { +module.exports = class Yaml extends BaseVersioning { /** * Bumps the version in the package.json @@ -53,5 +53,4 @@ module.exports = new (class Yaml extends BaseVersioning { } } -}) - +} diff --git a/test-file-2.json b/test-file-2.json new file mode 100644 index 0000000..2f7abc1 --- /dev/null +++ b/test-file-2.json @@ -0,0 +1,4 @@ +{ + "name": "Test JSON file 2", + "version": "1.4.5" +} diff --git a/test-output.js b/test-output.js index 8ae7821..495efb0 100644 --- a/test-output.js +++ b/test-output.js @@ -18,6 +18,8 @@ assert.ok(FILES, 'Files not defined!') * Test if all the files are updated */ FILES.split(',').map((file, index) => { + console.log(`Going to test file "${file}"`) + const fileContent = fs.readFileSync(file.trim(), 'utf8') const fileExtension = file.split('.').pop() @@ -43,8 +45,12 @@ FILES.split(',').map((file, index) => { assert.fail('File extension not supported!') } + console.log(`"${file}" has a valid extension "${fileExtension.toLowerCase()}"`) + assert.ok(parsedContent, 'Content could not be parsed!') + console.log(`"${file}" has valid content`, parsedContent) + const newVersionInFile = objectPath.get(parsedContent, EXPECTED_VERSION_PATH, null) const expectedVersions = EXPECTED_VERSION.split(',') @@ -52,6 +58,8 @@ FILES.split(',').map((file, index) => { ? expectedVersions[index] : expectedVersions + console.log(`"${file}" check if "${newVersionInFile}" matches what is expected "${expectedVersion.trim()}"`) + assert.strictEqual(newVersionInFile, expectedVersion.trim(), 'Version does not match what is expected') })