Skip to content

Commit

Permalink
Setup Travis and add tests (#12)
Browse files Browse the repository at this point in the history
* Add tests

* Setup travis

* Fix tests

* Update test name
  • Loading branch information
rogeliog committed Jul 3, 2018
1 parent a3c8e28 commit f3759ce
Show file tree
Hide file tree
Showing 11 changed files with 1,237 additions and 268 deletions.
16 changes: 2 additions & 14 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,16 +1,4 @@
language: node_js
node_js:
- 8
- node
- 6
script:
- yarn lint
- yarn test --coverage
cache:
yarn: true
branches:
only:
- master
# Practical when batching releases
- next
- "/^greenkeeper/.*$/"
- "8"
- "6"
28 changes: 17 additions & 11 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,25 +10,21 @@
"url": "https://github.com/jest-community/jest-watch-typeahead.git"
},
"homepage": "https://github.com/jest-community/jest-watch-typeahead",
"files": [
"build/",
"filename.js",
"testname.js"
],
"files": ["build/", "filename.js", "testname.js"],
"scripts": {
"test": "jest",
"lint": "eslint .",
"watch": "babel src -w --ignore **/*.test.js,integration -d build",
"build": "babel src --ignore **/*.test.js,integration -d build",
"prepublish": "yarn build",
"format": "prettier --single-quote --trailing-comma all --write \"!(build)/**/*.js\""
"format":
"prettier --single-quote --trailing-comma all --write \"!(build)/**/*.js\""
},
"dependencies": {
"chalk": "^2.3.1",
"chalk": "^2.4.1",
"jest-watcher": "^23.1.0",
"slash": "^1.0.0",
"string-length": "^2.0.0",
"strip-ansi": "^4.0.0"
"string-length": "^2.0.0"
},
"devDependencies": {
"babel-cli": "6.26.0",
Expand All @@ -43,7 +39,17 @@
"eslint-plugin-jest": "21.12.2",
"eslint-plugin-prettier": "2.6.0",
"flow-bin": "^0.66.0",
"jest": "22.4.2",
"prettier": "1.11.1"
"jest": "23.2.0",
"prettier": "1.11.1",
"strip-ansi": "^4.0.0"
},
"jest": {
"snapshotSerializers": [
"<rootDir>/node_modules/pretty-format/build/plugins/convert_ansi"
],
"testPathIgnorePatterns": [
"<rootDir>/build/.*",
"<rootDir>/src/__tests__/pluginTester.js"
]
}
}
103 changes: 103 additions & 0 deletions src/__tests__/__snapshots__/file_name_pattern_prompt.test.js.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`can select a pattern that matches multiple files 1`] = `
pattern › f
[MOCK - cursorSavePosition]
Pattern matches 3 files
› src/foo.js
› src/file-1.js
› src/file-2.js
[MOCK - cursorTo(12, 5)]
[MOCK - cursorRestorePosition]
pattern › fi
[MOCK - cursorSavePosition]
Pattern matches 2 files
› src/file-1.js
› src/file-2.js
[MOCK - cursorTo(13, 5)]
[MOCK - cursorRestorePosition]
`;

exports[`can use arrows to select a specific file 1`] = `
pattern › f
[MOCK - cursorSavePosition]
Pattern matches 3 files
› src/foo.js
› src/file-1.js
› src/file-2.js
[MOCK - cursorTo(12, 5)]
[MOCK - cursorRestorePosition]
pattern › fi
[MOCK - cursorSavePosition]
Pattern matches 2 files
› src/file-1.js
› src/file-2.js
[MOCK - cursorTo(13, 5)]
[MOCK - cursorRestorePosition]
pattern › fi
[MOCK - cursorSavePosition]
Pattern matches 2 files
› src/file-1.js
› src/file-2.js
[MOCK - cursorTo(13, 5)]
[MOCK - cursorRestorePosition]
`;

exports[`shows the correct initial state 1`] = `
[MOCK - cursorHide]
[MOCK - clearScreen]
Pattern Mode Usage
› Press Esc to exit pattern mode.
› Press Enter to filter by a filenames regex pattern.
[MOCK - cursorShow]
pattern ›
[MOCK - cursorSavePosition]
Start typing to filter by a filename regex pattern.
[MOCK - cursorTo(11, 5)]
[MOCK - cursorRestorePosition]
`;
121 changes: 121 additions & 0 deletions src/__tests__/__snapshots__/test_name_pattern_prompt.test.js.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`can select a pattern that matches multiple tests 1`] = `
pattern › f
[MOCK - cursorSavePosition]
Pattern matches 2 tests from cached test suites
› foo 1
› foo 2
[MOCK - cursorTo(12, 5)]
[MOCK - cursorRestorePosition]
pattern › fo
[MOCK - cursorSavePosition]
Pattern matches 2 tests from cached test suites
› foo 1
› foo 2
[MOCK - cursorTo(13, 5)]
[MOCK - cursorRestorePosition]
`;

exports[`can use arrows to select a specific test 1`] = `
pattern › f
[MOCK - cursorSavePosition]
Pattern matches 2 tests from cached test suites
› foo 1
› foo 2
[MOCK - cursorTo(12, 5)]
[MOCK - cursorRestorePosition]
pattern › f
[MOCK - cursorSavePosition]
Pattern matches 2 tests from cached test suites
› foo 1
› foo 2
[MOCK - cursorTo(12, 5)]
[MOCK - cursorRestorePosition]
pattern › f
[MOCK - cursorSavePosition]
Pattern matches 2 tests from cached test suites
› foo 1
› foo 2
[MOCK - cursorTo(12, 5)]
[MOCK - cursorRestorePosition]
`;

exports[`shows the correct initial state 1`] = `
[MOCK - cursorHide]
[MOCK - clearScreen]
Pattern Mode Usage
› Press Esc to exit pattern mode.
› Press Enter to filter by a tests regex pattern.
[MOCK - cursorShow]
pattern ›
[MOCK - cursorSavePosition]
Start typing to filter by a test name regex pattern.
[MOCK - cursorTo(11, 5)]
[MOCK - cursorRestorePosition]
`;

exports[`shows the correct message when there are no cached tests 1`] = `
[MOCK - cursorHide]
[MOCK - clearScreen]
Pattern Mode Usage
› Press Esc to exit pattern mode.
› Press Enter to filter by a tests regex pattern.
[MOCK - cursorShow]
pattern ›
[MOCK - cursorSavePosition]
Start typing to filter by a test name regex pattern.
[MOCK - cursorTo(11, 5)]
[MOCK - cursorRestorePosition]
`;
81 changes: 81 additions & 0 deletions src/__tests__/file_name_pattern_prompt.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
import { KEYS } from 'jest-watcher';
import pluginTester from './pluginTester';
import FileNamePlugin from '../file_name_plugin';

const projects = [
{
config: {
rootDir: '/project',
},
testPaths: ['/project/src/foo.js', '/project/src/file-1.js'],
},
{
config: {
rootDir: '/project',
},
testPaths: ['/project/src/bar.js', '/project/src/file-2.js'],
},
];

it('shows the correct initial state', async () => {
const {
stdout,
hookEmitter,
updateConfigAndRun,
plugin,
type,
} = pluginTester(FileNamePlugin);

hookEmitter.onFileChange({ projects });
const runPromise = plugin.run({}, updateConfigAndRun);
expect(stdout.write.mock.calls.join('\n')).toMatchSnapshot();
type(KEYS.ENTER);

await runPromise;
});

it('can use arrows to select a specific file', async () => {
const {
stdout,
hookEmitter,
updateConfigAndRun,
plugin,
type,
} = pluginTester(FileNamePlugin);

hookEmitter.onFileChange({ projects });
const runPromise = plugin.run({}, updateConfigAndRun);
stdout.write.mockReset();
type('f', 'i', KEYS.ARROW_DOWN, KEYS.ENTER);
expect(stdout.write.mock.calls.join('\n')).toMatchSnapshot();

await runPromise;

expect(updateConfigAndRun).toHaveBeenCalledWith({
mode: 'watch',
testPathPattern: 'src/file-1.js',
});
});

it('can select a pattern that matches multiple files', async () => {
const {
stdout,
hookEmitter,
updateConfigAndRun,
plugin,
type,
} = pluginTester(FileNamePlugin);

hookEmitter.onFileChange({ projects });
const runPromise = plugin.run({}, updateConfigAndRun);
stdout.write.mockReset();
type('f', 'i', KEYS.ENTER);
expect(stdout.write.mock.calls.join('\n')).toMatchSnapshot();

await runPromise;

expect(updateConfigAndRun).toHaveBeenCalledWith({
mode: 'watch',
testPathPattern: 'fi',
});
});
Loading

0 comments on commit f3759ce

Please sign in to comment.