Skip to content

Commit

Permalink
test(deps): delete moment from the test (#56)
Browse files Browse the repository at this point in the history
* test(deps): delete `moment` from the test

* test: use `replace` instead of `replaceAll`

* test: specify locale and remove `,`
  • Loading branch information
yoshinorin authored Oct 15, 2022
1 parent 924dba5 commit 0f22e09
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 8 deletions.
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,7 @@
"chai": "^4.3.6",
"eslint": "^8.23.1",
"eslint-config-hexo": "^5.0.0",
"mocha": "^10.0.0",
"moment": "^2.29.4"
"mocha": "^10.0.0"
},
"engines": {
"node": ">=14"
Expand Down
34 changes: 28 additions & 6 deletions test/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
'use strict';

const should = require('chai').should(); // eslint-disable-line
const moment = require('moment');

describe('Front-matter', () => {
const yfm = require('..');
Expand Down Expand Up @@ -340,21 +339,44 @@ describe('Front-matter', () => {

// Date parsing bug (issue #1)
it('date', () => {
const now = moment();
const unixTime = Date.now();
const stringifyDateTime = new Date(unixTime)
.toLocaleString(
'en-CA', {
year: 'numeric',
month: '2-digit',
day: '2-digit',
hour: '2-digit',
hour12: false,
minute: '2-digit',
second: '2-digit'
}
).replace(/,/g, '');

const str = [
`date: ${now.format('YYYY-MM-DD HH:mm:ss')}`,
`date: ${stringifyDateTime}`,
'---'
].join('\n');

const data = yfm.parse(str);
parseInt(data.date.getTime() / 1000, 10).should.eql(parseInt(now.valueOf() / 1000, 10));
parseInt(data.date.getTime() / 1000, 10).should.eql(parseInt(unixTime / 1000, 10));
});
});

describe('stringify', () => {
it('yaml', () => {
const now = new Date();
const now = new Date()
.toLocaleString(
'en-CA', {
year: 'numeric',
month: '2-digit',
day: '2-digit',
hour: '2-digit',
hour12: false,
minute: '2-digit',
second: '2-digit'
}
).replace(/,/g, '');

const data = {
layout: 'post',
Expand All @@ -365,7 +387,7 @@ describe('Front-matter', () => {

yfm.stringify(data).should.eql([
'layout: post',
`created: ${moment(now).format('YYYY-MM-DD HH:mm:ss')}`,
`created: '${now}'`,
'blank:',
'---',
'123'
Expand Down

0 comments on commit 0f22e09

Please sign in to comment.