Skip to content

Commit

Permalink
Merge pull request #510 from dilanx:automated-testing
Browse files Browse the repository at this point in the history
Added unit and integration testing through Github Actions on push/PR
  • Loading branch information
dilanx committed May 14, 2023
2 parents 42c756c + dc2ed70 commit 510a61b
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 9 deletions.
27 changes: 27 additions & 0 deletions .github/workflows/run-tests.yml
@@ -0,0 +1,27 @@
name: tests

on:
push:
branches: [main]
pull_request:
branches: [main]

jobs:
build:
runs-on: ubuntu-latest

strategy:
matrix:
node-version: [16.x, 18.x]

steps:
- uses: actions/checkout@v2
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v2
with:
node-version: ${{ matrix.node-version }}
- run: npm ci
- run: CI=false npm run build
- run: npm run test:unit
- run: npx playwright install-deps
- run: CI=false npm run test:integration
2 changes: 1 addition & 1 deletion README.md
Expand Up @@ -13,7 +13,7 @@

<br>

[![npm status](https://img.shields.io/npm/v/@craco/craco.svg)](https://www.npmjs.com/package/@craco/craco) [![npm downloads](https://img.shields.io/npm/dm/@craco/craco.svg)](https://www.npmjs.com/package/@craco/craco) [![npm license](https://img.shields.io/npm/l/@craco/craco?color=orange)](https://github.com/dilanx/craco/blob/main/packages/craco/LICENSE) [![GitHub stars](https://img.shields.io/github/stars/dilanx/craco?color=red)](https://github.com/dilanx/craco) [![GitHub contributors](https://img.shields.io/github/contributors/dilanx/craco?color=blueviolet)](https://github.com/dilanx/craco/graphs/contributors) [![PRs Welcome](https://img.shields.io/badge/PRs-welcome-blueviolet.svg)](https://github.com/dilanx/craco/pulls)
[![npm status](https://img.shields.io/npm/v/@craco/craco.svg)](https://www.npmjs.com/package/@craco/craco) [![npm downloads](https://img.shields.io/npm/dm/@craco/craco.svg)](https://www.npmjs.com/package/@craco/craco) [![npm license](https://img.shields.io/npm/l/@craco/craco?color=orange)](https://github.com/dilanx/craco/blob/main/packages/craco/LICENSE) [![GitHub stars](https://img.shields.io/github/stars/dilanx/craco?color=red)](https://github.com/dilanx/craco) [![GitHub contributors](https://img.shields.io/github/contributors/dilanx/craco?color=blueviolet)](https://github.com/dilanx/craco/graphs/contributors) [![PRs Welcome](https://img.shields.io/badge/PRs-welcome-blueviolet.svg)](https://github.com/dilanx/craco/pulls) ![Node.js CI](https://github.com/dilanx/craco/actions/workflows/run-tests.yml/badge.svg)

</div>

Expand Down
Expand Up @@ -15,7 +15,7 @@ beforeAll(async () => {

// Leave time for the server to initialize
await new Promise((resolve) => {
setTimeout(resolve, 3000);
setTimeout(resolve, 5000);
});
});

Expand All @@ -31,7 +31,7 @@ test('Should have the expected styles', async () => {

afterAll(() => {
// Stop the local server
execSync(`kill $(lsof -t -i:${global.PORT})`, {
execSync(`kill $(lsof -t -i:${global.PORT} -a -c node)`, {
cwd: __dirname,
stdio: 'ignore',
});
Expand Down
3 changes: 2 additions & 1 deletion test/integration/jest.config.js
Expand Up @@ -10,13 +10,14 @@ module.exports = {
moduleNameMapper: {
'\\.(css|less|scss|sass)$': 'identity-obj-proxy',
},
setupFiles: ['./setup.js'],
globalSetup: './setup.js',
globalTeardown: './teardown.js',
testEnvironmentOptions: {
'jest-playwright': {
browsers: ['firefox'],
launchOptions: {
headless: true,
timeout: 500000,
},
},
},
Expand Down
10 changes: 5 additions & 5 deletions test/integration/setup.js
Expand Up @@ -29,18 +29,18 @@ module.exports = async function (globalConfig, projectConfig) {
`cd ${join(
rootPath,
directoryName
)}&& npx create-react-app test-project`,
{ cwd: cwd }
)} && npx create-react-app test-project`,
{ cwd: cwd, stdio: 'inherit' }
);
execSync(`cp -r ${testPackageFilesPath}/* ${testProjectPath}`, {
cwd: cwd,
cwd: cwd
});
//install craco
execSync(`npm install ../../../../../packages/craco`, {
cwd: testProjectPath,
cwd: testProjectPath, stdio: 'inherit'
});
//install other necessary files
execSync(`npm install`, { cwd: testProjectPath });
execSync(`npm install`, { cwd: testProjectPath, stdio: 'inherit' });
//build project
execSync('npm run build', { cwd: testProjectPath, stdio: 'inherit' });
});
Expand Down

0 comments on commit 510a61b

Please sign in to comment.