Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Moved typings into repo, and updated typings to improve type safety. #302

Merged
merged 2 commits into from
Mar 2, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions no-important.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './typings';
10 changes: 8 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,11 @@
],
"main": "lib/index.js",
"module": "es/index.js",
"typings": "typings/index.d.ts",
"scripts": {
"lint": "eslint --fix --cache . && flow check",
"lint": "npm-run-all --parallel lint:*",
"lint:js": "eslint --fix --cache . && flow check",
"lint:ts": "tslint --project tsconfig.json --fix",
"test": "npm run coverage",
"posttest": "npm run lint",
"coverage": "nyc --check-coverage --lines 100 --branches 100 npm run tests",
Expand Down Expand Up @@ -47,6 +50,7 @@
"chai": "^3.3.0",
"coveralls": "^2.12.0",
"cross-env": "^5.1.3",
"cross-spawn": "^6.0.4",
"eslint": "^3.7.1",
"eslint-config-standard-react": "^4.2.0",
"eslint-plugin-react": "^6.3.0",
Expand All @@ -62,7 +66,9 @@
"rollup-plugin-commonjs": "^8.2.1",
"rollup-plugin-node-resolve": "^3.0.0",
"rollup-plugin-replace": "^2.0.0",
"rollup-plugin-uglify": "^3.0.0"
"rollup-plugin-uglify": "^3.0.0",
"tslint": "^5.9.1",
"typescript": "^2.7.2"
},
"dependencies": {
"asap": "^2.0.3",
Expand Down
61 changes: 61 additions & 0 deletions tests-ts/aphrodite_test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import { css, minify, StyleSheet, StyleSheetServer, StyleSheetTestUtils } from '../typings';

// StyleSheet
const withNumberOrString = StyleSheet.create({
first: {
height: '',
width: 0,
},
});

const withPseudo = StyleSheet.create({
withHover: {
':hover': {
height: '',
width: 0,
},
},
});

const mapValue = new Map();
mapValue.set('position', 'absolute');
mapValue.set('width', 0);
const withMap = StyleSheet.create({ mapValue });

StyleSheet.rehydrate(['']);

StyleSheet.extend([{
selectorHandler: (selector, baseSelector, callback) => {
selector.toLowerCase();
baseSelector.toLowerCase();
callback('').toLowerCase();
return '';
},
}, {
selectorHandler: () => null,
}]);

// css
const withCreateNumberOrString = css(withNumberOrString.first);
const withCreatePseudo = css(withPseudo.withHover);
const withCreateMap = css(withMap.mapValue);
const withObject = css({});
const withUndefinied = css(undefined);
const withNull = css(null);
const withFalse = css(false);
const withArray = css([{}]);

// StyleSheetTestUtils
StyleSheetTestUtils.suppressStyleInjection();
StyleSheetTestUtils.clearBufferAndResumeStyleInjection();
StyleSheetTestUtils.getBufferedStyles()[0].toLowerCase();

// StyleSheetServer
const serverResult = StyleSheetServer.renderStatic(() => '');
serverResult.css.content.toLowerCase();
serverResult.css.renderedClassNames[0].toLowerCase();
serverResult.html.toLowerCase();

// minify
minify(true);
minify(false);
15 changes: 15 additions & 0 deletions tests/typescript_test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import {assert} from 'chai';
import spawn from 'cross-spawn'

describe('Typings', () => {
it('compiles successfully', () => {
const typescriptCompilation = spawn.sync('./node_modules/.bin/tsc', [
'-p',
'./tsconfig.json',
]);
const output = typescriptCompilation.stdout.toString();

assert.equal(output, '');
assert.equal(typescriptCompilation.status, 0);
}).timeout(5000);
});
20 changes: 20 additions & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"compilerOptions": {
"allowJs": false,
"inlineSources": true,
"module": "commonjs",
"moduleResolution": "node",
"noEmit": true,
"noImplicitAny": true,
"noImplicitReturns": true,
"noUnusedLocals": false,
"noUnusedParameters": false,
"removeComments": false,
"sourceMap": true,
"strictNullChecks": true,
"target": "es6"
},
"include": [
"./tests-ts"
]
}
12 changes: 12 additions & 0 deletions tslint.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"defaultSeverity": "error",
"extends": [
"tslint:recommended"
],
"jsRules": {},
"rules": {
"indent": [true, "spaces", 4],
"quotemark": [true, "single"]
},
"rulesDirectory": []
}
Loading