Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test a workflow for caching dependencies #9

Open
wants to merge 22 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
node_modules/
coverage/
__tests__/
39 changes: 39 additions & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
{
"parser": "@babel/eslint-parser",
"env": {
"browser": true,
"node": true
},
"globals": {
"__MESSAGES__": true,
"__MESSAGING_GLOBALS__": true
},
"plugins": ["prettier"],
"rules": {
"arrow-body-style": "off",
"unicorn/prefer-spread": "off",
"prettier/prettier": "error",
"no-underscore-dangle": "off",
"no-promise-executor-return": "off",
"import/prefer-default-export": "off",
"react/jsx-indent": 0,
"react/jsx-indent-props": 0,
"react/prop-types": 0,
"react/function-component-definition": 0,
"react/jsx-one-expression-per-line": 0,
"react/jsx-filename-extension": 0,
"react/jsx-curly-spacing": 0,
"react/no-unknown-property": 0
},
"settings": {
"import/resolver": {
"babel-module": {
"alias": {
"src": "./src",
"server": "./server",
"utils": "./utils"
}
}
}
}
}
68 changes: 68 additions & 0 deletions .github/workflows/test-dependency-path.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
name: Test Caching For Dependencies

on:
push:
branches:
- 'test/cache-dependency'
pull_request:
branches:
- 'test/cache-dependency'

jobs:
test-caching-tests:
name: Test Caching Dependencies
runs-on: ubuntu-latest

steps:
- name: Checkout
uses: actions/checkout@v3

- name: Setup Node
uses: actions/setup-node@v3
with:
node-version-file: .nvmrc
cache: 'npm'
cache-dependency-path: ./package.json

- name: Install Dependencies
run: npm i

- name: Run unit tests
run: npm run test

- name: The job has succeeded
run: |
if [[ ${{ job.status }} == 'success' ]]; then
echo "All previous steps were successful"
else
echo "Some previous steps failed"
fi

test-caching-lint:
name: Run Linting Job
runs-on: ubuntu-latest

steps:
- name: Checkout
uses: actions/checkout@v3

- name: Setup Node
uses: actions/setup-node@v3
with:
node-version-file: .nvmrc
cache: 'npm'
cache-dependency-path: ./package.json

- name: Install Dependencies
run: npm i

- name: Lint
run: npm run lint

- name: The job has succeeded
run: |
if [[ ${{ job.status }} == 'success' ]]; then
echo "All previous steps were successful"
else
echo "Some previous steps failed"
fi
1 change: 1 addition & 0 deletions .nvmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
v16
18 changes: 18 additions & 0 deletions __tests__/index.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
const packageFunction = require('../index');

describe('myFunction', () => {
let consoleLogSpy;

beforeEach(() => {
consoleLogSpy = jest.spyOn(console, 'log').mockImplementation();
});

afterEach(() => {
consoleLogSpy.mockRestore();
});

it('should log the expected message', () => {
packageFunction();
expect(consoleLogSpy).toHaveBeenCalledWith("Testing");
});
});
6 changes: 6 additions & 0 deletions babel.config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"presets": ["@babel/preset-env"],
"ignore": [
"./node_modules"
]
}
7 changes: 6 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
@@ -1 +1,6 @@
console.log("Testing");
// file-to-test.js
function packageFunction() {
console.log("Testing");
}

module.exports = packageFunction;
Loading