Skip to content

Commit

Permalink
add simple testcase & update README
Browse files Browse the repository at this point in the history
  • Loading branch information
hustcc committed Mar 1, 2017
1 parent 61b4d34 commit c0dda99
Show file tree
Hide file tree
Showing 9 changed files with 34 additions and 13 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@
.DS_Store

node_modules/*
tests/test_ts.js

5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,14 @@ import timeago from 'timeago.js';
var timeago = require("timeago.js");
```

or link with `script` in html files:
or link with `script` in html files.

```js
<script src="dist/timeago.min.js"></script>
```

or import to a typescript file
or import to a typescript file.

```ts
impor timeago from 'timeago.js';

Expand Down
11 changes: 10 additions & 1 deletion README_zh.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ npm install timeago.js

**2. 引入 timeago.js**


使用import引入,然后可以得到一个全局变量: `timeago`.

```js
Expand All @@ -58,6 +57,16 @@ var timeago = require("timeago.js");
<script src="dist/timeago.min.js"></script>
```

或者在 typescript 文件中引入.

```ts
impor timeago from 'timeago.js';

// or

import timeago = require("timeago.js");
```

**3. 使用 `timeago`**

```js
Expand Down
6 changes: 4 additions & 2 deletions dist/timeago.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@
**/
/* jshint expr: true */
!function (root, factory) {
if (typeof module === 'object' && module.exports)
module.exports = factory(root);
if (typeof module === 'object' && module.exports) {
module.exports = factory(root); // nodejs support
module.exports['default'] = module.exports; // es6 support
}
else
root.timeago = factory(root);
}(typeof window !== 'undefined' ? window : this,
Expand Down
2 changes: 1 addition & 1 deletion dist/timeago.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 4 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,14 @@
"gulp-rename": "^1.2.2",
"gulp-uglify": "^2.0.0",
"jshint": "^2.9.2",
"pys": "^1.0.3",
"slice.js": "^1.0.3",
"tape": "^4.6.2",
"webpack": "^1.12.9"
"webpack": "^1.12.9",
"typescript": "^2.2.1"
},
"scripts": {
"lint": "jshint src/timeago.js",
"test": "npm run lint && node tests/locales_test.js && node tests/test.js",
"test": "npm run lint && node tests/locales_test.js && node tests/test.js && tsc tests/test_ts.ts && node tests/test_ts.js",
"test_dev": "npm run lint && node tests/test_dev.js",
"build": "gulp mini && webpack && npm run test"
},
Expand Down
4 changes: 2 additions & 2 deletions tests/locales_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@
const fs = require('fs');
const test = require('tape');
const timeago = require('..');
const pys = require('pys');
const slice = require('slice.js');

// all the locales code, if missing, please add them.
const allLocales = require('../locales/locales.js');

function testLocales(tobeTested) {
test('Testing locales', t => {
tobeTested.forEach(file => {
const localeName = pys(file)('0:-3');
const localeName = slice(file)('0:-3');
t.ok(allLocales.indexOf(localeName) >= 0, 'locale [' + localeName + ']');

console.log('\nTesting locales [' + localeName + ']');
Expand Down
4 changes: 2 additions & 2 deletions tests/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@
const test = require('tape');
const timeago = require('..');
const fs = require('fs');
const pys = require('pys');
const slice = require('slice.js');
const testBuilder = require('./test-builder');

test('timeago.js should be tested', t => {
// locale tests #################################################################
// read all the locales test in `tests/locales` dir
fs.readdir('tests/locales', (err, files) => {
files.forEach(file => {
const locale = pys(file)('0:-3');
const locale = slice(file)('0:-3');
console.log('\nLocale testcase for ['+ locale +']');
// require in the locales testcases
const tb = testBuilder(Date.now()).register(locale, require('../locales/' + locale), true);
Expand Down
7 changes: 7 additions & 0 deletions tests/test_ts.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// just test typescript can be compiled and ran.
// TODO: if trace or error, travis-ci will error

console.log('run typescript.')
import timeago from '..'
const timeagoInstance = timeago()
console.log(timeagoInstance.format('01-01-2017'))

0 comments on commit c0dda99

Please sign in to comment.