Skip to content

Commit 3fcb4bd

Browse files
committed
feat: handles stringifyContentPathRegex
1 parent ec271c7 commit 3fcb4bd

12 files changed

Lines changed: 125 additions & 79 deletions

.prettierignore

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
dist/
2+
e2e/
3+
!e2e/__helpers__
4+
!e2e/__serializers__
5+
!e2e/__tests__
6+
node_modules/
7+
src/**/__snapshots__/

.prettierrc

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
semi: true
2+
printWidth: 80
3+
singleQuote: true
4+
tabWidth: 2
5+
useTabs: false
6+
overrides:
7+
- files: "**/*.js"
8+
options:
9+
trailing-comma: es5
10+
- files: "**/*.ts"
11+
options:
12+
trailingComma: all

e2e/__tests__/hoisting.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { configureTestCase } from '../__helpers__/test-case';
22
import { allPackageSets } from '../__helpers__/templates';
33

44
describe('Hoisting test', () => {
5-
const testCase = configureTestCase('hoisting', { args: ['--no-cache'] });
5+
const testCase = configureTestCase('hoisting');
66

77
testCase.runWithTemplates(allPackageSets, 0, (runTest, { testLabel }) => {
88
it(testLabel, () => {

e2e/__tests__/simple.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { configureTestCase } from '../__helpers__/test-case';
22
import { allPackageSets } from '../__helpers__/templates';
33

44
describe('Simple test', () => {
5-
const testCase = configureTestCase('simple', { args: ['--no-cache'] });
5+
const testCase = configureTestCase('simple');
66

77
testCase.runWithTemplates(allPackageSets, 0, (runTest, { testLabel }) => {
88
it(testLabel, () => {

e2e/__tests__/source-map.test.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import { configureTestCase } from '../__helpers__/test-case';
22
import { allPackageSets } from '../__helpers__/templates';
33

44
const testCase = configureTestCase('source-maps', {
5-
args: ['--no-cache'],
65
writeIo: true,
76
});
87

package-lock.json

Lines changed: 7 additions & 14 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,7 @@
1818
"prepare": "npm run build",
1919
"prepublishOnly": "npm run test",
2020
"precommit": "lint-staged",
21-
"postcommit": "git reset",
22-
"format": "prettier --single-quote --trailing-comma all --write \"{src,scripts}/**/*.ts\" && prettier --single-quote --trailing-comma es5 --write \"{src,scripts}/**/*.js\""
21+
"postcommit": "git reset"
2322
},
2423
"repository": {
2524
"type": "git",
@@ -50,14 +49,14 @@
5049
"@types/gist-package-json": "git+https://gist.github.com/5c1cc527fe6b5b7dba41fec7fe54bf6e.git",
5150
"@types/jest": "^23.3.1",
5251
"@types/lodash.set": "^4.3.4",
53-
"@types/node": "^10.5.7",
52+
"@types/node": "^10.5.8",
5453
"closest-file-data": "^0.1.4",
5554
"cross-spawn": "^6.0.5",
5655
"doctoc": "^1.3.1",
5756
"fs-extra": "^7.0.0",
5857
"husky": "^0.14.3",
5958
"jest": "^23.4.1",
60-
"lint-staged": "^7.2.0",
59+
"lint-staged": "^7.2.2",
6160
"lodash.set": "^4.3.2",
6261
"npm-run-all": "^4.1.3",
6362
"prettier": "^1.14.2",
@@ -67,16 +66,14 @@
6766
"typescript": "^3.0.1"
6867
},
6968
"lint-staged": {
70-
"*.js": [
71-
"prettier --write --single-quote --trailing-comma es5",
72-
"git add"
73-
],
74-
"*.ts": [
75-
"prettier --write --single-quote --trailing-comma all",
76-
"git add"
77-
]
69+
"linters": {
70+
"*.{js,ts}": [
71+
"prettier --write",
72+
"git add"
73+
]
74+
}
7875
},
7976
"engines": {
8077
"node": ">= 6"
8178
}
82-
}
79+
}

src/__helpers__/fakers.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
import { TsJestGlobalOptions } from '../types';
2-
import { resolve, relative } from 'path';
3-
import spyThese from './spy-these';
4-
import realFs from 'fs';
2+
import { resolve } from 'path';
53

64
export function filePath(relPath: string): string {
75
return resolve(__dirname, '..', '..', relPath);
@@ -28,6 +26,14 @@ describe('hello', function () {
2826
`;
2927
}
3028

29+
export function htmlSource() {
30+
return `
31+
<div>
32+
<span>some text with \`backtilt\`</span>
33+
</div>
34+
`;
35+
}
36+
3137
export function typescriptSource() {
3238
return `
3339
import upper from './upper';

src/__snapshots__/ts-jest-transformer.spec.ts.snap

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,5 @@ var lower_1 = __importDefault(require(\\"./lower\\"));describe('hello', function
2727
});
2828
//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbImZpbGUudHMiXSwibmFtZXMiOlsiamVzdCIsIm1vY2siLCJzIiwidG9VcHBlckNhc2UiLCJfX2ltcG9ydERlZmF1bHQiLCJtb2QiLCJfX2VzTW9kdWxlIiwidXBwZXJfMSIsInJlcXVpcmUiLCJsb3dlcl8xIiwiZGVzY3JpYmUiLCJ0ZXN0IiwidG9Mb3dlckNhc2UiLCJleHBlY3QiLCJkZWZhdWx0IiwidG9CZSJdLCJtYXBwaW5ncyI6IjtBQUNBOztBQU1BQSxLQUFLQyxJQUFMLENBQVUsU0FBVixFQUFxQixZQUFZO0FBQUUsV0FBTyxVQUFVQyxDQUFWLEVBQWE7QUFBRSxlQUFPQSxFQUFFQyxXQUFGLEVBQVA7QUFBeUIsS0FBL0M7QUFBa0QsQ0FBckY7QUFMQSxJQUFJQyxrQkFBbUIsUUFBUSxLQUFLQSxlQUFkLElBQWtDLFVBQVVDLEdBQVYsRUFBZTtBQUNuRSxXQUFRQSxPQUFPQSxJQUFJQyxVQUFaLEdBQTBCRCxHQUExQixHQUFnQyxFQUFFLFdBQVdBLEdBQWIsRUFBdkM7QUFDSCxDQUZEO0FBR0EsSU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TtcbmRlc2NyaWJlKCdoZWxsbycsIGZ1bmN0aW9uICgpIHtcbiAgICB0ZXN0KCdteSB0ZXN0JywgZnVuY3Rpb24gKCkge1xuICAgICAgICBleHBlY3QodXBwZXJfMS5kZWZhdWx0KCdoZWxsbycpKS50b0JlKCdIRUxMTycpO1xuICAgICAgICBleHBlY3QobG93ZXJfMS5kZWZhdWx0KCdIRUxMTycpKS50b0JlKCdoZWxsbycpO1xuICAgICAgICBqZXN0Lm1vY2soJy4vbG93ZXInLCBmdW5jdGlvbiAoKSB7IHJldHVybiBmdW5jdGlvbiAocykgeyByZXR1cm4gcy50b0xvd2VyQ2FzZSgpOyB9OyB9KTtcbiAgICB9KTtcbn0pO1xuIl19"
2929
`;
30+
31+
exports[`process stringifyContentPathRegex should create a module with stringified content as export 1`] = `"module.exports=\\"\\\\n<div>\\\\n <span>some text with \`backtilt\`</span>\\\\n</div>\\\\n\\""`;

src/ts-jest-transformer.spec.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,28 @@ describe('process', () => {
4444
expect(result.code).toMatchSnapshot();
4545
});
4646
}); // hoisting
47+
48+
describe('stringifyContentPathRegex', () => {
49+
const transformer = new TsJestTransformer();
50+
it('should create a module with stringified content as export', () => {
51+
const config = fakers.jestConfig(
52+
{},
53+
{ stringifyContentPathRegex: '\\.html$' },
54+
);
55+
const source = fakers.htmlSource();
56+
const result = transformer.process(
57+
source,
58+
fakers.filePath('path/to/file.html'),
59+
config,
60+
) as string;
61+
expect(result).toMatchSnapshot();
62+
const importer = Function(
63+
`const exports = {}, module = {exports:exports};${result};return module.exports;`,
64+
);
65+
expect(importer).not.toThrow();
66+
expect(importer()).toEqual(source);
67+
});
68+
}); // stringifyContentPathRegex
4769
}); // process
4870

4971
describe('getCacheKey', () => {

0 commit comments

Comments
 (0)