diff --git a/e2e/__tests__/__snapshots__/coverageHandlebars.test.ts.snap b/e2e/__tests__/__snapshots__/coverageHandlebars.test.ts.snap new file mode 100644 index 000000000000..88c38c8fb9b9 --- /dev/null +++ b/e2e/__tests__/__snapshots__/coverageHandlebars.test.ts.snap @@ -0,0 +1,371 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`code coverage for Handlebars 1`] = ` +Object { + "greet.hbs": Object { + "b": Object { + "0": Array [ + 2, + 0, + ], + "1": Array [ + 1, + 0, + ], + "2": Array [ + 1, + 0, + ], + "3": Array [ + 1, + 1, + ], + "4": Array [ + 1, + 1, + ], + "5": Array [ + 1, + 0, + ], + }, + "branchMap": Object { + "0": Object { + "loc": Object { + "end": Object { + "column": null, + "line": 6, + }, + "start": Object { + "column": 2, + "line": 6, + }, + }, + "locations": Array [ + Object { + "end": Object { + "column": null, + "line": 6, + }, + "start": Object { + "column": 2, + "line": 6, + }, + }, + Object { + "end": Object { + "column": null, + "line": 6, + }, + "start": Object { + "column": 2, + "line": 6, + }, + }, + ], + "type": "cond-expr", + }, + "1": Object { + "loc": Object { + "end": Object { + "column": 6, + "line": 8, + }, + "start": Object { + "column": 0, + "line": 8, + }, + }, + "locations": Array [ + Object { + "end": Object { + "column": 6, + "line": 8, + }, + "start": Object { + "column": 0, + "line": 8, + }, + }, + Object { + "end": Object { + "column": 6, + "line": 8, + }, + "start": Object { + "column": 0, + "line": 8, + }, + }, + ], + "type": "cond-expr", + }, + "2": Object { + "loc": Object { + "end": Object { + "column": 10, + "line": 8, + }, + "start": Object { + "column": 6, + "line": 8, + }, + }, + "locations": Array [ + Object { + "end": Object { + "column": 10, + "line": 8, + }, + "start": Object { + "column": 6, + "line": 8, + }, + }, + Object { + "end": Object { + "column": 10, + "line": 8, + }, + "start": Object { + "column": 6, + "line": 8, + }, + }, + ], + "type": "cond-expr", + }, + "3": Object { + "loc": Object { + "end": Object { + "column": 2, + "line": 13, + }, + "start": Object { + "column": 0, + "line": 13, + }, + }, + "locations": Array [ + Object { + "end": Object { + "column": 2, + "line": 13, + }, + "start": Object { + "column": 0, + "line": 13, + }, + }, + Object { + "end": Object { + "column": 2, + "line": 13, + }, + "start": Object { + "column": 0, + "line": 13, + }, + }, + ], + "type": "cond-expr", + }, + "4": Object { + "loc": Object { + "end": Object { + "column": 2, + "line": 13, + }, + "start": Object { + "column": 0, + "line": 13, + }, + }, + "locations": Array [ + Object { + "end": Object { + "column": 2, + "line": 13, + }, + "start": Object { + "column": 0, + "line": 13, + }, + }, + Object { + "end": Object { + "column": 8, + "line": 13, + }, + "start": Object { + "column": 2, + "line": 13, + }, + }, + ], + "type": "binary-expr", + }, + "5": Object { + "loc": Object { + "end": Object { + "column": 8, + "line": 13, + }, + "start": Object { + "column": 2, + "line": 13, + }, + }, + "locations": Array [ + Object { + "end": Object { + "column": 8, + "line": 13, + }, + "start": Object { + "column": 2, + "line": 13, + }, + }, + Object { + "end": Object { + "column": 8, + "line": 13, + }, + "start": Object { + "column": 2, + "line": 13, + }, + }, + ], + "type": "cond-expr", + }, + }, + "f": Object { + "0": 1, + "1": 0, + "2": 1, + }, + "fnMap": Object { + "0": Object { + "decl": Object { + "end": Object { + "column": null, + "line": 8, + }, + "start": Object { + "column": 10, + "line": 8, + }, + }, + "loc": Object { + "end": Object { + "column": null, + "line": 8, + }, + "start": Object { + "column": 10, + "line": 8, + }, + }, + "name": "(anonymous_0)", + }, + "1": Object { + "decl": Object { + "end": Object { + "column": null, + "line": 10, + }, + "start": Object { + "column": 8, + "line": 10, + }, + }, + "loc": Object { + "end": Object { + "column": null, + "line": 10, + }, + "start": Object { + "column": 8, + "line": 10, + }, + }, + "name": "(anonymous_1)", + }, + "2": Object { + "decl": Object { + "end": Object { + "column": null, + "line": 6, + }, + "start": Object { + "column": 2, + "line": 6, + }, + }, + "loc": Object { + "end": Object { + "column": null, + "line": 6, + }, + "start": Object { + "column": 2, + "line": 6, + }, + }, + "name": "(anonymous_2)", + }, + }, + "path": "greet.hbs", + "s": Object { + "0": 1, + "1": 0, + "2": 2, + "3": 1, + }, + "statementMap": Object { + "0": Object { + "end": Object { + "column": null, + "line": 8, + }, + "start": Object { + "column": 10, + "line": 8, + }, + }, + "1": Object { + "end": Object { + "column": null, + "line": 10, + }, + "start": Object { + "column": 8, + "line": 10, + }, + }, + "2": Object { + "end": Object { + "column": null, + "line": 6, + }, + "start": Object { + "column": 2, + "line": 6, + }, + }, + "3": Object { + "end": Object { + "column": null, + "line": 13, + }, + "start": Object { + "column": 2, + "line": 6, + }, + }, + }, + }, +} +`; diff --git a/e2e/__tests__/coverageHandlebars.test.ts b/e2e/__tests__/coverageHandlebars.test.ts new file mode 100644 index 000000000000..a07e5c529b80 --- /dev/null +++ b/e2e/__tests__/coverageHandlebars.test.ts @@ -0,0 +1,38 @@ +/** + * Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + */ + +import {readFileSync} from 'fs'; +import * as path from 'path'; +import {cleanup, run} from '../Utils'; +import runJest from '../runJest'; + +const dir = path.resolve(__dirname, '../coverage-handlebars'); +const coverageDir = path.join(dir, 'coverage'); + +beforeAll(() => { + cleanup(coverageDir); +}); + +it('code coverage for Handlebars', () => { + run('yarn', dir); + const result = runJest(dir, ['--coverage', '--no-cache']); + + expect(result.exitCode).toBe(0); + + const coverageMapFile = path.join(coverageDir, 'coverage-final.json'); + const coverageMap = JSON.parse(readFileSync(coverageMapFile, 'utf-8')); + + // reduce absolute paths embedded in the coverage map to just filenames + Object.keys(coverageMap).forEach(filename => { + coverageMap[filename].path = path.basename(coverageMap[filename].path); + delete coverageMap[filename].hash; + coverageMap[path.basename(filename)] = coverageMap[filename]; + delete coverageMap[filename]; + }); + expect(coverageMap).toHaveProperty(['greet.hbs']); + expect(coverageMap).toMatchSnapshot(); +}); diff --git a/e2e/coverage-handlebars/__tests__/greet.js b/e2e/coverage-handlebars/__tests__/greet.js new file mode 100644 index 000000000000..f5775645112e --- /dev/null +++ b/e2e/coverage-handlebars/__tests__/greet.js @@ -0,0 +1,13 @@ +/* + * Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + */ +const greet = require('../greet.hbs'); + +test('am', () => { + expect(greet({am: true, name: 'Joe'})).toEqual( + '
Good\n morning\nJoe!
\n' + ); +}); diff --git a/e2e/coverage-handlebars/greet.hbs b/e2e/coverage-handlebars/greet.hbs new file mode 100644 index 000000000000..9dd3847305ae --- /dev/null +++ b/e2e/coverage-handlebars/greet.hbs @@ -0,0 +1,13 @@ +{{! + * Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. +}} +Good +{{#if am}} + morning +{{else}} + evening +{{/if}} +{{name}}!
diff --git a/e2e/coverage-handlebars/package.json b/e2e/coverage-handlebars/package.json new file mode 100644 index 000000000000..3eb23f01b754 --- /dev/null +++ b/e2e/coverage-handlebars/package.json @@ -0,0 +1,12 @@ +{ + "jest": { + "transform": { + "\\.hbs$": "