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

chore: add create-jest-runner; update/fix all tests #34

Merged
merged 50 commits into from
Sep 18, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
50 commits
Select commit Hold shift + click to select a range
f09a516
init from jest-runner-mocha
rogeliog Sep 8, 2017
8211827
WIP
rogeliog Oct 5, 2017
d46549e
Some cleanup
rogeliog Oct 17, 2017
fc25c86
First working example of create-jest-runner
rogeliog Oct 17, 2017
9507482
v0.1.0
rogeliog Oct 17, 2017
d7242f1
Update jest-worker to support tty
rogeliog Nov 22, 2017
35d7c19
Add changelog
rogeliog Nov 22, 2017
256848d
v0.1.1
rogeliog Nov 22, 2017
2ef0132
added skip functionality with test
lgandecki Jan 20, 2018
928c853
wrong test title
lgandecki Jan 20, 2018
c13f6fc
v0.2.0-0
rogeliog Jan 23, 2018
c7a864a
v0.2.0
rogeliog Jan 25, 2018
5aaefd2
update new code location of test result
DanielMSchmidt Mar 1, 2018
37e66e1
Mutex the test runs
stipsan Mar 20, 2018
610c917
typo, damn github web ui
stipsan Mar 20, 2018
0e64137
async is actually not needed here
stipsan Mar 20, 2018
701e91f
feat: support serial execution
SimenB Mar 22, 2018
d163e97
Prepare 0.3.0 release
rogeliog Mar 27, 2018
30716f9
v0.3.0
rogeliog Mar 27, 2018
46791ae
use import/export (#8)
SimenB Mar 28, 2018
37d568b
feat: add mutex to in band runner (#7)
SimenB Apr 27, 2018
025e58a
Add travis badge
SimenB Apr 27, 2018
431f029
Removing un-needed packages (#1)
kesne Apr 28, 2018
abf53a4
Prepare 0.3.1
rogeliog Apr 29, 2018
26100d2
v0.3.1
rogeliog Apr 29, 2018
4e82e7c
Drop node 4 (#11)
SimenB May 27, 2018
ad623d4
Create LICENSE
SimenB Jun 7, 2018
4e22487
Add getExtraOptions to entry file (#12)
rogeliog Jun 10, 2018
b363e62
Prepare 0.4.0
rogeliog Jun 10, 2018
b792047
v0.4.0
rogeliog Jun 10, 2018
f3a8b8e
fix: update dated deps (#13)
SimenB Sep 21, 2018
ce1a8e0
v0.4.1
SimenB Sep 21, 2018
4de30de
feat: bump jest 24; add `todo` helper (#14)
thymikee Feb 2, 2019
74f4d94
chore: update lockfile
SimenB Feb 2, 2019
501d058
0.5.0
SimenB Feb 2, 2019
2cbcf37
chore: update changelog
SimenB Feb 2, 2019
63a8ba6
Fix README.md link to TestResult type (#16)
elliottsj Apr 23, 2019
3aa9b3e
feat: add binary to scaffold new runner (#17)
Mark1626 Jun 3, 2019
5cb0d66
v0.5.1
SimenB Jun 3, 2019
85bd1d3
v0.5.2
SimenB Jun 3, 2019
436ee82
fix: add missing files to package (#18)
skratchdot Jun 7, 2019
f16ad2a
make tests pass by disabling colors
tunnckoCore Sep 17, 2019
aa3a497
changes for #20
tunnckoCore Sep 17, 2019
4ecc331
fix linting, ignore fixtures dirs
tunnckoCore Sep 17, 2019
55abd79
update prepublish script
tunnckoCore Sep 17, 2019
7667a34
oops, fix the version, as it was from the beginning
tunnckoCore Sep 17, 2019
bd54068
oops, fix the name
tunnckoCore Sep 17, 2019
0968481
use prepublishOnly script
tunnckoCore Sep 17, 2019
c082263
update scripts
tunnckoCore Sep 17, 2019
54381f5
chore: add create-jest-runner; make tests pass
tunnckoCore Sep 18, 2019
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
15 changes: 15 additions & 0 deletions @tunnckocore/create-jest-runner/.vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"editor.rulers": [80],
"files.exclude": {
"**/.git": true,
"**/node_modules": true,
"**/build": true
},
"prettier.parser": "flow",
"prettier.printWidth": 80,
"prettier.singleQuote": true,
"prettier.trailingComma": "all",
"prettier.semi": true,
"editor.formatOnSave": true,
"prettier.eslintIntegration": true
}
42 changes: 42 additions & 0 deletions @tunnckocore/create-jest-runner/__support__/runJest.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/* eslint-disable import/no-extraneous-dependencies */
const execa = require('execa');
const path = require('path');
const { stripColor } = require('ansi-colors');

const rootDir = path.dirname(__dirname);

const normalize = (output) =>
output
.replace(/\(?\d*\.?\d+m?s\)?/g, '')
.replace(/, estimated/g, '')
.replace(new RegExp(rootDir, 'g'), '/mocked-path-to-jest-runner-mocha')
.replace(new RegExp('.*at .*\\n', 'g'), 'mocked-stack-trace')
.replace(/.*at .*\\n/g, 'mocked-stack-trace')
.replace(/(mocked-stack-trace)+/, ' at mocked-stack-trace')
.replace(/\s+\n/g, '\n');

const runJest = (project, options = []) => {
// eslint-disable-next-line no-undef
jest.setTimeout(15000);

return execa(
'jest',
[
'--useStderr',
'--no-watchman',
'--no-cache',
'--projects',
path.join(rootDir, '__tests__', '__fixtures__', project),
].concat(options),
{
env: process.env,
reject: false,
},
// eslint-disable-next-line promise/prefer-await-to-then
).then(
({ stdout, stderr }) =>
`${stripColor(normalize(stderr))}\n${stripColor(normalize(stdout))}`,
);
};

module.exports = runJest;
3 changes: 3 additions & 0 deletions @tunnckocore/create-jest-runner/__support__/runner/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
const { createJestRunner } = require('../../');

module.exports = createJestRunner(require.resolve('./run'));
24 changes: 24 additions & 0 deletions @tunnckocore/create-jest-runner/__support__/runner/run.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
const fs = require('fs');
const { pass, fail, skip, todo } = require('../../');

module.exports = ({ testPath }) => {
const start = Date.now();
const contents = fs.readFileSync(testPath, 'utf8');
const end = Date.now();

if (contents.includes('⚔️🏃')) {
return pass({ start, end, test: { path: testPath } });
}
if (contents.includes('🙈')) {
return skip({ start, end, test: { path: testPath } });
}
if (contents.includes('📃')) {
return todo({ start, end, test: { path: testPath } });
}
const errorMessage = 'Company policies require ⚔️ 🏃 in every file';
return fail({
start,
end,
test: { path: testPath, errorMessage, title: 'Check for ⚔️ 🏃' },
});
};
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
console.log();
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module.exports = {
runner: require.resolve('../../../__support__/runner'),
testMatch: ['**/__src__/**/*.js'],
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
// ⚔️🏃
console.log();
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module.exports = {
runner: require.resolve('../../../__support__/runner'),
testMatch: ['**/__src__/**/*.js'],
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
// 🙈
console.log();
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module.exports = {
runner: require.resolve('../../../__support__/runner'),
testMatch: ['**/__src__/**/*.js'],
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
// 📃
console.log();
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module.exports = {
runner: require.resolve('../../../__support__/runner'),
testMatch: ['**/__src__/**/*.js'],
};
6 changes: 6 additions & 0 deletions @tunnckocore/create-jest-runner/__tests__/failing.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
const runJest = require('../__support__/runJest');

it('Works when it has failing tests', async () => {
const resultString = await runJest('failing');
expect(resultString).toEqual(expect.stringContaining('1 failed, 1 total'));
});
6 changes: 6 additions & 0 deletions @tunnckocore/create-jest-runner/__tests__/passing.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
const runJest = require('../__support__/runJest');

it('Works when it has only passing tests', async () => {
const resultString = await runJest('passing');
expect(resultString).toEqual(expect.stringContaining('1 passed, 1 total'));
});
6 changes: 6 additions & 0 deletions @tunnckocore/create-jest-runner/__tests__/skipped.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
const runJest = require('../__support__/runJest');

it('Works when it has skipped tests', async () => {
const resultString = await runJest('skipped');
expect(resultString).toEqual(expect.stringContaining('1 skipped, 1 total'));
});
7 changes: 7 additions & 0 deletions @tunnckocore/create-jest-runner/__tests__/todo.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
const runJest = require('../__support__/runJest');

it('Works when it has todo tests', async () => {
const resultString = await runJest('todo');
expect(resultString).toEqual(expect.stringContaining('1 passed, 1 total'));
expect(resultString).toEqual(expect.stringContaining('1 todo, 1 total'));
});
21 changes: 21 additions & 0 deletions @tunnckocore/create-jest-runner/generator/config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
module.exports = {
dirs: ['src'],
createList: [
{
input: '_package.json',
output: 'package.json',
},
{
input: '_README.md',
output: 'README.md',
},
{
input: 'index.js',
output: 'src/index.js',
},
{
input: 'run.js',
output: 'src/run.js',
},
],
};
43 changes: 43 additions & 0 deletions @tunnckocore/create-jest-runner/generator/fixtures/_README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# generated-jest-runner

## Usage

### Install

Install `jest`_(it needs Jest 21+)_ and `generated-jest-runner`

```bash
yarn add --dev jest generated-jest-runner

# or with NPM

npm install --save-dev jest generated-jest-runner
```

## Add your runner to Jest config

Once you have your Jest runner you can add it to your Jest config.

In your `package.json`

```json
{
"jest": {
"runner": "generated-jest-runner"
}
}
```

Or in `jest.config.js`

```js
module.exports = {
runner: require.resolve('generated-jest-runner'),
};
```

### Run Jest

```bash
yarn jest
```
16 changes: 16 additions & 0 deletions @tunnckocore/create-jest-runner/generator/fixtures/_package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"name": "generated-jest-runner",
"version": "1.0.0",
"description": "A generated jest runner",
"main": "src/index.js",
"scripts": {
"test": "jest"
},
"jest": {
"runner": "./test/runner"
},
"dependencies": {
"jest": "^24.6.0",
"create-jest-runner": "^0.5.0"
}
}
4 changes: 4 additions & 0 deletions @tunnckocore/create-jest-runner/generator/fixtures/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
// eslint-disable-next-line import/no-extraneous-dependencies
const { createJestRunner } = require('@tunnckocore/create-jest-runner');

module.exports = createJestRunner(require.resolve('./run'));
19 changes: 19 additions & 0 deletions @tunnckocore/create-jest-runner/generator/fixtures/run.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
const fs = require('fs');
// eslint-disable-next-line import/no-extraneous-dependencies
const { pass, fail } = require('@tunnckocore/create-jest-runner');

module.exports = ({ testPath }) => {
const start = Date.now();
const contents = fs.readFileSync(testPath, 'utf8');
const end = Date.now();

if (contents.includes('⚔️🏃')) {
return pass({ start, end, test: { path: testPath } });
}
const errorMessage = 'Company policies require ⚔️ 🏃 in every file';
return fail({
start,
end,
test: { path: testPath, errorMessage, title: 'Check for ⚔️ 🏃' },
});
};
53 changes: 53 additions & 0 deletions @tunnckocore/create-jest-runner/generator/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
#!/usr/bin/env node
/* eslint-disable no-console */

const fs = require('fs');
const path = require('path');
const { blue, red, green, yellow, magenta } = require('chalk');
const config = require('./config');

const createIfNotExists = folder => {
if (!fs.existsSync(folder)) {
console.log(`Creating new jest-runner in ${green(folder)}`);
fs.mkdirSync(folder);
} else {
throw new Error('Folder already exists');
}
};

const scaffoldRunner = () => {
try {
const fixturesPath = path.resolve(__dirname, 'fixtures');
let outputDirname;
const projectName = process.argv[2];
if (projectName) {
outputDirname = path.resolve('.', projectName);
createIfNotExists(outputDirname);
} else {
throw new Error('Project name not specified');
}

config.dirs.forEach(item => {
console.log(`Creating ${blue('directory')} ${magenta(item)}`);
fs.mkdirSync(path.resolve(outputDirname, item));
});

config.createList.forEach(file => {
const filePath = path.resolve(outputDirname, file.output);
const content = fs.readFileSync(path.resolve(fixturesPath, file.input));
console.log(`Creating ${yellow('file')} ${magenta(file.output)}`);
fs.writeFileSync(filePath, content);
});
console.log(green('Scaffolding successfull'));
console.log(blue('Run cd npm/yarn install'));
console.log(red('Update the package name package.json'));
} catch (e) {
console.log(`${red('Scaffolding failed')} ${e}`);
}
};

scaffoldRunner();

module.exports = {
scaffoldRunner,
};
43 changes: 43 additions & 0 deletions @tunnckocore/create-jest-runner/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
{
"version": "0.5.4",
"name": "@tunnckocore/create-jest-runner",
"description": "WIP",
"author": "Charlike Mike Reagent <[email protected]>",
"homepage": "https://github.com/tunnckoCore/opensource",
"license": "MPL-2.0",
"licenseStart": 2019,
"main": "dist/main/index.js",
"module": "dist/module/index.js",
"types": "dist/types/index.d.ts",
"scripts": {},
"publishConfig": {
"access": "public",
"tag": "latest"
},
"engines": {
"node": ">=8.11"
},
"repository": {
"type": "git",
"url": "https://github.com/tunnckoCore/opensource.git",
"directory": "@tunnckocore/create-jest-runner"
},
"dependencies": {
"chalk": "^2.4.2",
"jest-worker": "^24.0.0",
"throat": "^4.1.0"
},
"devDependencies": {
"ansi-colors": "^4.1.1",
"execa": "^1.0.0",
"jest": "^24.0.0"
},
"peerDependencies": {},
"files": [
"dist",
"generator"
],
"bin": {
"create-jest-runner": "./generator/index.js"
}
}
Loading