Add jest and basic unit tests.
This commit is contained in:
Родитель
10aca74973
Коммит
95c0e6d7bf
|
@ -20,7 +20,7 @@ steps:
|
|||
#- script: |
|
||||
# git config user.email "jagore@microsoft.com"
|
||||
# git config user.name "jagore@microsoft.com"
|
||||
# git remote set-url origin https://$(github.user):$(github.pat)@github.com/JasonGore/flamegrill.git
|
||||
# git remote set-url origin https://$(github.user):$(github.pat)@github.com/microsoft/flamegrill.git
|
||||
# displayName: 'git config'
|
||||
|
||||
- script: |
|
||||
|
@ -31,9 +31,9 @@ steps:
|
|||
yarn build
|
||||
displayName: 'build'
|
||||
|
||||
#- script: |
|
||||
# yarn test
|
||||
# displayName: 'test'
|
||||
- script: |
|
||||
yarn test
|
||||
displayName: 'test'
|
||||
|
||||
#- script: |
|
||||
# yarn pub -n $(npm.authtoken) -y
|
||||
|
|
|
@ -18,15 +18,15 @@ steps:
|
|||
|
||||
- script: |
|
||||
yarn build
|
||||
displayName: 'yarn build'
|
||||
displayName: 'build'
|
||||
|
||||
#- script: |
|
||||
# yarn test
|
||||
# displayName: 'yarn test'
|
||||
- script: |
|
||||
yarn test
|
||||
displayName: 'test'
|
||||
|
||||
#- script: |
|
||||
# yarn checkchange
|
||||
# displayName: 'yarn checkchange'
|
||||
# displayName: 'checkchange'
|
||||
|
||||
- task: ComponentGovernanceComponentDetection@0
|
||||
inputs:
|
||||
|
|
|
@ -3,12 +3,13 @@
|
|||
"private": true,
|
||||
"version": "0.0.1",
|
||||
"main": "index.js",
|
||||
"repository": "https://github.com/JasonGore/flamegrill.git",
|
||||
"repository": "https://github.com/microsoft/flamegrill.git",
|
||||
"author": "Jason Gore <jagore@microsoft.com>",
|
||||
"license": "MIT",
|
||||
"scripts": {
|
||||
"build": "lerna run build --stream",
|
||||
"build:flamegrill": "lerna run build --scope flamegrill",
|
||||
"test": "lerna run test --scope flamegrill",
|
||||
"start": "lerna run start",
|
||||
"change": "node ./packages/flamegrill/lib/cli.js change",
|
||||
"checkchange": "node ./packages/flamegrill/lib/cli.js check",
|
||||
|
|
|
@ -0,0 +1,8 @@
|
|||
module.exports = {
|
||||
"roots": [
|
||||
"<rootDir>/src"
|
||||
],
|
||||
"transform": {
|
||||
"^.+\\.tsx?$": "ts-jest"
|
||||
},
|
||||
}
|
|
@ -9,10 +9,12 @@
|
|||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/JasonGore/flamegrill"
|
||||
"url": "https://github.com/microsoft/flamegrill"
|
||||
},
|
||||
"scripts": {
|
||||
"build": "just-scripts build",
|
||||
"test": "jest",
|
||||
"test-watch": "jest --watch",
|
||||
"start": "tsc -w --preserveWatchOutput"
|
||||
},
|
||||
"dependencies": {
|
||||
|
@ -24,9 +26,12 @@
|
|||
},
|
||||
"devDependencies": {
|
||||
"@types/concat-stream": "^1.6.0",
|
||||
"@types/jest": "^24.0.17",
|
||||
"@types/puppeteer": "^1.12.4",
|
||||
"@types/yargs-parser": "^13.0.0",
|
||||
"jest": "^24.8.0",
|
||||
"just-scripts": "0.28.0",
|
||||
"ts-jest": "^24.0.2",
|
||||
"typescript": "^3.5.1"
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,69 @@
|
|||
import { checkForRegressions, FunctionData, __unitTestHooks } from '../processData';
|
||||
|
||||
const { filterMinifiedNames, filterSystemNames } = __unitTestHooks;
|
||||
|
||||
function constructFunctionData(names: string[], defaultFiltered?: boolean): FunctionData[] {
|
||||
return names.map(name => ({
|
||||
name,
|
||||
displayName: '',
|
||||
filtered: defaultFiltered,
|
||||
index: 0,
|
||||
instances: []
|
||||
}));
|
||||
}
|
||||
|
||||
describe('processData', () => {
|
||||
describe('checkForRegressions', () => {
|
||||
});
|
||||
|
||||
describe('filterMinifiedNames', () => {
|
||||
const testMinifiedNames = [
|
||||
'~j ',
|
||||
'~Rp ',
|
||||
'~z.J ',
|
||||
'~render ',
|
||||
'~(anonymous)',
|
||||
'validFunction',
|
||||
'(unknown)',
|
||||
'~webpack'
|
||||
];
|
||||
|
||||
it('filters out minified names', () => {
|
||||
const testFunctions = constructFunctionData(testMinifiedNames);
|
||||
const filteredNames = filterMinifiedNames(testFunctions);
|
||||
|
||||
expect(filteredNames).toHaveLength(8);
|
||||
expect(filteredNames.filter(item => !item.filtered)).toHaveLength(1);
|
||||
expect(filteredNames.filter(item => item.name === 'validFunction' && !item.filtered)).toHaveLength(1);
|
||||
});
|
||||
|
||||
it('respects previously filtered names', () => {
|
||||
const testFunctions = constructFunctionData(testMinifiedNames, true);
|
||||
const filteredNames = filterMinifiedNames(testFunctions);
|
||||
|
||||
expect(filteredNames).toHaveLength(8);
|
||||
expect(filteredNames.filter(item => !item.filtered)).toHaveLength(0);
|
||||
});
|
||||
});
|
||||
|
||||
describe('filterSystemNames', () => {
|
||||
const testSystemNames = [ '(C++)', '(lib)', 'validFunction' ];
|
||||
|
||||
it('filters out system names', () => {
|
||||
const testFunctions = constructFunctionData(testSystemNames);
|
||||
const filteredNames = filterSystemNames(testFunctions);
|
||||
|
||||
expect(filteredNames).toHaveLength(3);
|
||||
expect(filteredNames.filter(item => !item.filtered)).toHaveLength(1);
|
||||
expect(filteredNames.filter(item => item.name === 'validFunction' && !item.filtered)).toHaveLength(1);
|
||||
});
|
||||
|
||||
it('respects previously filtered names', () => {
|
||||
const testFunctions = constructFunctionData(testSystemNames, true);
|
||||
const filteredNames = filterSystemNames(testFunctions);
|
||||
|
||||
expect(filteredNames).toHaveLength(3);
|
||||
expect(filteredNames.filter(item => !item.filtered)).toHaveLength(0);
|
||||
});
|
||||
});
|
||||
});
|
|
@ -289,6 +289,11 @@ function filterSystemNames(functions: FunctionData[]): FunctionData[] {
|
|||
return functions;
|
||||
}
|
||||
|
||||
export const __unitTestHooks = {
|
||||
filterMinifiedNames,
|
||||
filterSystemNames
|
||||
};
|
||||
|
||||
if (require.main === module) {
|
||||
// From directory with output:
|
||||
// node ..\..\..\node_modules\flamegrill\lib\analysis\processData.js > ../analysis.txt
|
||||
|
|
|
@ -13,7 +13,7 @@ export interface GeneratedFiles {
|
|||
|
||||
const tickprocessor = require.resolve('../tickprocessor');
|
||||
|
||||
// TODO: can remove this if not using Node
|
||||
// TODO: no longer using Node's profile processor, remove this
|
||||
function jsonCleanUp() {
|
||||
return new Transform({
|
||||
transform: (data, _, next) => {
|
||||
|
|
|
@ -51,7 +51,7 @@ export interface Analyses {
|
|||
[key: string]: Analysis;
|
||||
};
|
||||
|
||||
export async function cook(scenarios: Scenario[], config: ScenarioConfig) {
|
||||
export async function cook(scenarios: Scenario[], config: ScenarioConfig): Promise<Analyses> {
|
||||
// const extraV8Flags = '--log-source-code --log-timer-events';
|
||||
// const extraV8Flags = '--log-source-code';
|
||||
const extraV8Flags = '';
|
||||
|
|
1684
yarn.lock
1684
yarn.lock
Разница между файлами не показана из-за своего большого размера
Загрузить разницу
Загрузка…
Ссылка в новой задаче