Skip to content

Commit

Permalink
test(ical2json): Convert test files to TS
Browse files Browse the repository at this point in the history
  • Loading branch information
adrianlee44 committed Jan 5, 2021
1 parent 50052a5 commit adbf94c
Show file tree
Hide file tree
Showing 8 changed files with 721 additions and 437 deletions.
1,010 changes: 644 additions & 366 deletions package-lock.json

Large diffs are not rendered by default.

12 changes: 7 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,11 @@
"license": "MIT",
"bin": "bin/ical2json",
"devDependencies": {
"@types/mock-fs": "^4.13.0",
"@types/node": "^14.0.1",
"@typescript-eslint/eslint-plugin": "^3.0.0",
"@typescript-eslint/parser": "^3.0.0",
"ava": "^3.7.0",
"ava": "^3.15.0",
"coveralls": "^3.0.11",
"eslint": "^6.8.0",
"eslint-config-prettier": "^6.11.0",
Expand All @@ -47,17 +48,18 @@
"mock-fs": "^4.11.0",
"nyc": "^15.0.1",
"prettier": "^2.0.5",
"ts-node": "^9.1.1",
"typescript": "^3.8.3"
},
"dependencies": {
"commander": "^5.0.0"
},
"ava": {
"require": [
"esm"
"extensions": [
"ts"
],
"files": [
"test/*.js"
"require": [
"ts-node/register"
]
}
}
11 changes: 7 additions & 4 deletions test/cli.js → test/cli.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import mock from 'mock-fs';
import * as mock from 'mock-fs';
import {existsSync, writeFileSync, readFileSync} from 'fs';
import run from '../build/cli';
import {convert} from '../build/ical2json';
import test from 'ava';
import run from '../src/cli';
import {convert} from '../src/ical2json';
import anyTest, {TestInterface} from 'ava';

const test = anyTest as TestInterface<{eventString: string}>;

test.before((t) => {
mock();
Expand All @@ -21,6 +23,7 @@ test.after(() => {

test('read ics and write json', (t) => {
run({
revert: false,
args: ['doesNotExist.ics', 'wrongExt.data', 'test.ics'],
});
t.false(existsSync('doesNotExist.json'));
Expand Down
4 changes: 2 additions & 2 deletions test/ical2json.js → test/ical2json.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {convert, revert} from '../build/ical2json';
import {convert, revert} from '../src/ical2json';
import test from 'ava';

test('converting VEVENT', (t) => {
Expand All @@ -22,7 +22,7 @@ test('missing :', (t) => {
});

test('converting and reverting result in same content', (t) => {
const normalize = (text) => text.replace(/\n\s?/g, '');
const normalize = (text: string) => text.replace(/\n\s?/g, '');

const sampleContent =
"BEGIN:VEVENT\nDTSTART;VALUE=DATE:20130101\nDTEND;VALUE=DATE:20130102\nDTSTAMP:20111213T124028Z\nRDATE:20111213T124028Z\nRDATE:20111213T124028Z\nUID:9d6fa48343f70300fe3109efe@calendarlabs.com\nCREATED:20111213T123901Z\nDESCRIPTION:Visit http://calendarlabs.com/holidays/us/new-years-day.php to kn\n ow more about New Year's Day. Like us on Facebook: http://fb.com/calendarlabs to get updates.\nLAST-MODIFIED:20111213T123901Z\nLOCATION:\nSEQUENCE:0\nSTATUS:CONFIRMED\nSUMMARY:New Year's Day\nTRANSP:TRANSPARENT\nEND:VEVENT";
Expand Down
Binary file removed test/snapshots/ical2json.js.snap
Binary file not shown.
116 changes: 58 additions & 58 deletions test/snapshots/ical2json.js.md → test/snapshots/ical2json.ts.md
Original file line number Diff line number Diff line change
@@ -1,46 +1,8 @@
# Snapshot report for `test/ical2json.js`
# Snapshot report for `test/ical2json.ts`

The actual snapshot is saved in `ical2json.js.snap`.
The actual snapshot is saved in `ical2json.ts.snap`.

Generated by [AVA](https://ava.li).

## RFC example 1

> Snapshot 1
{
VCALENDAR: [
{
PRODID: '-//xyz Corp//NONSGML PDA Calendar Version 1.0//EN',
VERSION: '2.0',
VEVENT: [
{
CATEGORIES: 'CONFERENCE',
DESCRIPTION: 'Networld+Interop Conference and Exhibit Atlanta World Congress Center Atlanta, Georgia',
DTEND: '19960920T220000Z',
DTSTAMP: '19960704T120000Z',
DTSTART: '19960918T143000Z',
ORGANIZER: 'mailto:jsmith@example.com',
STATUS: 'CONFIRMED',
SUMMARY: 'Networld+Interop Conference',
UID: 'uid1@example.com',
},
],
},
],
}

## converting CR and making sure CR is handled correctly

> Snapshot 1
{
VEVENT: [
{
'DTSTART;VALUE=DATE': '20130101',
},
],
}
Generated by [AVA](https://avajs.dev).

## converting VEVENT

Expand All @@ -65,29 +27,26 @@ Generated by [AVA](https://ava.li).
],
}

## converting multi-child w/o BEGIN-END
## converting CR and making sure CR is handled correctly

> Snapshot 1
{
VEVENT: [
{
'DTSTART;VALUE=DATE': '20130101',
},
],
}

## converting old newline and making sure CR is handled correctly

> Snapshot 1
{
VEVENT: [
{
CREATED: '20111213T123901Z',
DESCRIPTION: 'Visit http://calendarlabs.com/holidays/us/new-years-day.php to know more about New Year\'s Day. Like us on Facebook: http://fb.com/calendarlabs to get updates.',
'DTEND;VALUE=DATE': '20130102',
DTSTAMP: '20111213T124028Z',
'DTSTART;VALUE=DATE': '20130101',
EXDATE: [
'20111215T093000',
'20111216T093000',
],
'LAST-MODIFIED': '20111213T123901Z',
LOCATION: '',
SEQUENCE: '0',
STATUS: 'CONFIRMED',
SUMMARY: 'New Year\'s Day',
TRANSP: 'TRANSPARENT',
UID: '9d6fa48343f70300fe3109efe@calendarlabs.com',
},
],
}
Expand Down Expand Up @@ -123,14 +82,29 @@ Generated by [AVA](https://ava.li).
],
}

## converting old newline and making sure CR is handled correctly
## converting multi-child w/o BEGIN-END

> Snapshot 1
{
VEVENT: [
{
CREATED: '20111213T123901Z',
DESCRIPTION: 'Visit http://calendarlabs.com/holidays/us/new-years-day.php to know more about New Year\'s Day. Like us on Facebook: http://fb.com/calendarlabs to get updates.',
'DTEND;VALUE=DATE': '20130102',
DTSTAMP: '20111213T124028Z',
'DTSTART;VALUE=DATE': '20130101',
EXDATE: [
'20111215T093000',
'20111216T093000',
],
'LAST-MODIFIED': '20111213T123901Z',
LOCATION: '',
SEQUENCE: '0',
STATUS: 'CONFIRMED',
SUMMARY: 'New Year\'s Day',
TRANSP: 'TRANSPARENT',
UID: '9d6fa48343f70300fe3109efe@calendarlabs.com',
},
],
}
Expand Down Expand Up @@ -170,3 +144,29 @@ Generated by [AVA](https://ava.li).
},
],
}

## RFC example 1

> Snapshot 1
{
VCALENDAR: [
{
PRODID: '-//xyz Corp//NONSGML PDA Calendar Version 1.0//EN',
VERSION: '2.0',
VEVENT: [
{
CATEGORIES: 'CONFERENCE',
DESCRIPTION: 'Networld+Interop Conference and Exhibit Atlanta World Congress Center Atlanta, Georgia',
DTEND: '19960920T220000Z',
DTSTAMP: '19960704T120000Z',
DTSTART: '19960918T143000Z',
ORGANIZER: 'mailto:jsmith@example.com',
STATUS: 'CONFIRMED',
SUMMARY: 'Networld+Interop Conference',
UID: 'uid1@example.com',
},
],
},
],
}
Binary file added test/snapshots/ical2json.ts.snap
Binary file not shown.
5 changes: 3 additions & 2 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@
"module": "commonjs",
"outDir": "./build",
"strict": true,
"rootDir": "./src",
"rootDirs": ["src", "test"],
"types": ["node"],
"declaration": true
}
},
"include": ["src/**/*"]
}

0 comments on commit adbf94c

Please sign in to comment.