Skip to content

Commit

Permalink
fix: lint + github action (#31)
Browse files Browse the repository at this point in the history
* fix: lint + github action

* feat(test): adds sonarcloud to test.yml

* Removes coverage threshold
  • Loading branch information
bezoerb authored Apr 27, 2022
1 parent d29aa0a commit 49a20ee
Show file tree
Hide file tree
Showing 7 changed files with 121 additions and 27 deletions.
46 changes: 46 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
name: Tests

on: [push, pull_request]

env:
CI: true

jobs:
run:
name: Node ${{ matrix.node }} on ${{ matrix.os }}
runs-on: ${{ matrix.os }}

strategy:
fail-fast: false
matrix:
node: [14, 16]
os: [ubuntu-latest]

steps:
- name: Clone repository
uses: actions/checkout@v2

- name: Set up Node.js
uses: actions/setup-node@v2
with:
node-version: ${{ matrix.node }}

- name: Cache Node Modules
id: cache-node-modules
uses: actions/cache@v2
with:
path: node_modules
key: node-modules-${{ hashFiles('package-lock.json') }}

- name: Install dependencies
run: npm ci

- name: Run tests
run: npm test

- name: SonarCloud Scan
uses: SonarSource/sonarcloud-github-action@master
if: startsWith(matrix.os, 'ubuntu') && startsWith(matrix.node, '16')
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Needed to get PR information, if any
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ pids
lib-cov

# Coverage directory used by tools like istanbul
__coverage__
coverage
*.lcov

Expand Down
20 changes: 10 additions & 10 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,16 @@
* });
*
*/
const { getValidationHelpers } = require('./lib/helpers/validation');
const { getLocaleHelpers } = require('./lib/helpers/locale');
const { getValidationHelpers } = require('./lib/helpers/validation');
const { getLocaleHelpers } = require('./lib/helpers/locale');

// Export wrapper
module.exports.withHelpers = (cb) => (migration, context) => {
const locale = getLocaleHelpers(migration, context);
const validation = getValidationHelpers(migration, context);
// Export wrapper
module.exports.withHelpers = (cb) => (migration, context) => {
const locale = getLocaleHelpers(migration, context);
const validation = getValidationHelpers(migration, context);

return cb(migration, context, { locale, validation });
};
return cb(migration, context, { locale, validation });
};

module.exports.getValidationHelpers = getValidationHelpers;
module.exports.getLocaleHelpers = getLocaleHelpers;
module.exports.getValidationHelpers = getValidationHelpers;
module.exports.getLocaleHelpers = getLocaleHelpers;
6 changes: 4 additions & 2 deletions lib/migration.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,12 @@ const fetchMigration = async (config) => {
.toString()
// Add call to utils.getDefaultLocale() to the top
.replace(
'module.exports = function (migration) {',`
'module.exports = function (migration) {',
`
${migrationHeader}
const defaultLocale = helpers.locale.getDefaultLocale();
`)
`
)
// Replace the default locale with defaultLocale.code so that the migration
// still works as expected when the locale is changed in contentful
.replace(testDefaultValueRegex, '$1[defaultLocale.code]$2')
Expand Down
34 changes: 34 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

26 changes: 11 additions & 15 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"migrations": "cli.js"
},
"scripts": {
"test": "jest && npm run lint",
"test": "jest --coverage && npm run lint",
"lint": "eslint . --ext .js,.ts,.tsx --ignore-path .gitignore",
"fix-lint": "npm run lint -- --fix"
},
Expand Down Expand Up @@ -68,6 +68,7 @@
"eslint-plugin-prettier": "^4.0.0",
"husky": "^7.0.4",
"jest": "^27.5.1",
"jest-sonar-reporter": "^2.0.0",
"lint-staged": "^12.1.2"
},
"publishConfig": {
Expand All @@ -78,6 +79,9 @@
"printWidth": 120
},
"eslintConfig": {
"ignorePatterns": [
"**/*.d.ts"
],
"plugins": [
"prettier"
],
Expand Down Expand Up @@ -110,24 +114,11 @@
]
},
"jest": {
"testResultsProcessor": "jest-sonar-reporter",
"coverageDirectory": "<rootDir>/__coverage__/",
"collectCoverageFrom": [
"<rootDir>/lib/*/**"
],
"coverageThreshold": {
"global": {
"statements": 85,
"branches": 80,
"functions": 80,
"lines": 85
},
"**/*": {
"statements": 75,
"branches": 70,
"functions": 70,
"lines": 75
}
},
"roots": [
"<rootDir>/lib/"
],
Expand All @@ -154,5 +145,10 @@
"storage": "content",
"migrationContentTypeId": "contentful-migrations",
"directory": "migrations"
},
"jestSonar": {
"reportPath": "__coverage__",
"reportFile": "test-report.xml",
"indent": 2
}
}
15 changes: 15 additions & 0 deletions sonar-project.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
sonar.projectKey=jungvonmatt_contentful-migrations
sonar.organization=jungvonmatt

# This is the name and version displayed in the SonarCloud UI.
#sonar.projectName=contentful-migrations
#sonar.projectVersion=1.0

# Path is relative to the sonar-project.properties file. Replace "\" by "/" on Windows.
#sonar.sources=.

# Encoding of the source code. Default is default system encoding
#sonar.sourceEncoding=UTF-8

sonar.testExecutionReportPaths=__coverage__/test-report.xml
sonar.javascript.lcov.reportPaths=__coverage__/lcov.info

0 comments on commit 49a20ee

Please sign in to comment.