Skip to content

Commit

Permalink
add fixture
Browse files Browse the repository at this point in the history
  • Loading branch information
sw-yx committed Aug 26, 2019
1 parent a7b09da commit 990f115
Show file tree
Hide file tree
Showing 11 changed files with 1,483 additions and 0 deletions.
7 changes: 7 additions & 0 deletions test/fixtures/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
## Fixtures testing

here are some fixtures for manual testing things we don't have Jest tests for.

- `build-default` focuses on our zero config defaults
- `build-invalid` lets us check what happens when we have invalid builds due to type errors
- `build-withConfig` lets us check that `tsdx.config.js` works as expected
9 changes: 9 additions & 0 deletions test/fixtures/build-withConfig/errors/ErrorDev.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@

function ErrorDev(message) {
const error = new Error(message);
error.name = 'Invariant Violation';
return error;
}

export default ErrorDev;

15 changes: 15 additions & 0 deletions test/fixtures/build-withConfig/errors/ErrorProd.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@

function ErrorProd(code) {
// TODO: replace this URL with yours
let url = 'https://reactjs.org/docs/error-decoder.html?invariant=' + code;
for (let i = 1; i < arguments.length; i++) {
url += '&args[]=' + encodeURIComponent(arguments[i]);
}
return new Error(
`Minified BuildWithconfig error #${code}; visit ${url} for the full message or ` +
'use the non-minified dev environment for full errors and additional ' +
'helpful warnings. '
);
}

export default ErrorProd;
4 changes: 4 additions & 0 deletions test/fixtures/build-withConfig/errors/codes.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"0": "this is an old error that shouldn't be overwritten",
"1": "error occurred! o no"
}
17 changes: 17 additions & 0 deletions test/fixtures/build-withConfig/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"scripts": {
"build": "tsdx build --extractErrors"
},
"name": "build-withconfig",
"license": "MIT",
"dependencies": {
"tiny-invariant": "^1.0.6",
"tiny-warning": "^1.0.3"
},
"devDependencies": {
"autoprefixer": "^9.6.1",
"cssnano": "^4.1.10",
"eslint-config-postcss": "^3.0.7",
"rollup-plugin-postcss": "^2.0.3"
}
}
1 change: 1 addition & 0 deletions test/fixtures/build-withConfig/src/foo.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const foo = () => 'bar';
12 changes: 12 additions & 0 deletions test/fixtures/build-withConfig/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import invariant from 'tiny-invariant';
import warning from 'tiny-warning';
invariant(true, 'error occurred! o no');
warning(false, 'warning - water is wet');
export { foo } from './foo';

export const sum = (a: number, b: number) => {
if ('development' === process.env.NODE_ENV) {
console.log('fuck');
}
return a + b;
};
7 changes: 7 additions & 0 deletions test/fixtures/build-withConfig/test/blah.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { sum } from '../src';

describe('fuck', () => {
it('works', () => {
expect(sum(1, 1)).toEqual(2);
});
});
29 changes: 29 additions & 0 deletions test/fixtures/build-withConfig/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{
"compilerOptions": {
"target": "es5",
"module": "ESNext",
"lib": ["dom", "esnext"],
"declaration": true,
"sourceMap": true,
"rootDir": "./",
"strict": true,
"noImplicitAny": true,
"strictNullChecks": true,
"strictFunctionTypes": true,
"strictPropertyInitialization": true,
"noImplicitThis": true,
"alwaysStrict": true,
"noUnusedLocals": true,
"noUnusedParameters": true,
"noImplicitReturns": true,
"noFallthroughCasesInSwitch": true,
"moduleResolution": "node",
"baseUrl": "./",
"paths": {
"*": ["src/*", "node_modules/*"]
},
"jsx": "react",
"esModuleInterop": true
},
"include": ["src", "types"],
}
22 changes: 22 additions & 0 deletions test/fixtures/build-withConfig/tsdx.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
const postcss = require('rollup-plugin-postcss');
const autoprefixer = require('autoprefixer');
const cssnano = require('cssnano');

module.exports = {
rollup(config, options) {
config.plugins.push(
postcss({
plugins: [
autoprefixer(),
cssnano({
preset: 'default',
}),
],
inject: false,
// only write out CSS for the first bundle (avoids pointless extra files):
extract: !!options.writeMeta,
})
);
return config;
},
};
Loading

0 comments on commit 990f115

Please sign in to comment.