-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #148 from bindable-ui/dd/search3
Fix highlight phrase
- Loading branch information
Showing
6 changed files
with
92 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
#! /usr/bin/env node | ||
/* eslint-disable no-console */ | ||
const path = require('path'); | ||
const chalk = require('chalk'); | ||
const fs = require('fs'); | ||
const childProcess = require('child_process'); | ||
const opn = require('opn'); | ||
|
||
const args = process.argv.slice(2); | ||
|
||
const showUsage = () => { | ||
console.log(chalk.yellow('Usage:')); | ||
console.log(chalk.yellow('--------------------------------------------------------------')); | ||
console.log(chalk.yellow('[**/*.test.js] # test file with coverage report')); | ||
console.log(chalk.yellow('--nowatch # turn off watcher')); | ||
console.log(chalk.yellow('open # opens the coverage report')); | ||
console.log(chalk.yellow('--help # display this message')); | ||
console.log(chalk.yellow('--------------------------------------------------------------')); | ||
}; | ||
|
||
let command = 'node_modules/jest/bin/jest.js --watch'; | ||
let openCoverageReport = false; | ||
if (args.length === 0) { | ||
showUsage(); | ||
return; | ||
} | ||
args.forEach(entry => { | ||
if (entry === '-h' || entry === '--help') { | ||
showUsage(); | ||
} else if (entry === '--nowatch') { | ||
command = command.replace('--watch', ''); | ||
} else if (entry === 'open') { | ||
openCoverageReport = true; | ||
command = command.replace('--watch', ''); | ||
} else { | ||
if (!fs.existsSync(entry)) { | ||
console.log(chalk.red(`Error!! Test file: ${entry} doesn't exist.`)); | ||
process.exit(); | ||
return; | ||
} | ||
command += ` ${entry}`; | ||
|
||
const {dir, name, ext} = path.parse(entry); | ||
const filename = name.replace('.test', '') + ext; | ||
const searchPath = `${dir}/${filename}`; | ||
const exists = fs.existsSync(searchPath); | ||
if (!exists) { | ||
console.log(chalk.red(`Error!! Original file: ${searchPath} doesn't exist.`)); | ||
} else { | ||
command += ` --coverage --collectCoverageFrom=${searchPath}`; | ||
} | ||
} | ||
}); | ||
|
||
command += ' --color always'; | ||
try { | ||
console.log(command); | ||
childProcess.execSync(command, {stdio: 'inherit'}); | ||
if (openCoverageReport) { | ||
opn('./test/coverage-jest/index.html', {wait: false}); | ||
} | ||
} catch (e) {} // eslint-disable-line no-empty |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import {highlightSearchPhrases} from './highlight-phrases'; | ||
|
||
describe('Highlight Search Phrases Helper', () => { | ||
it('should highlight selected search phrases', () => { | ||
const searchPhrases = ['dumb', 'and']; | ||
const desc = 'Dumb and Dumber'; | ||
const highlighted = highlightSearchPhrases(searchPhrases, desc); | ||
expect(highlighted).toEqual( | ||
'<span style="background-color: #226684;">Dumb</span> ' + | ||
'<span style="background-color: #226684;">and</span> ' + | ||
'<span style="background-color: #226684;">Dumb</span>er', | ||
); | ||
const empty = highlightSearchPhrases(searchPhrases); | ||
expect(empty).toEqual(''); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters