@@ -88,7 +88,8 @@ test('"data help" prints help message', async t => {
8888 t . is ( result . code , 0 )
8989 const stdout = result . stdout . split ( '\n' )
9090 t . true ( stdout . length > 1 )
91- t . true ( stdout [ 1 ] . includes ( '❒ data [options] <command> <args>' ) )
91+ const hasExpectedMsg = stdout . find ( item => item . includes ( '❒ data [options] <command> <args>' ) )
92+ t . truthy ( hasExpectedMsg )
9293} )
9394
9495
@@ -99,16 +100,20 @@ test('get command with local dataset', async t => {
99100 const identifier = 'test/fixtures/finance-vix'
100101 const result = await runcli ( 'get' , identifier )
101102 const stdout = result . stdout . split ( '\n' )
102- t . true ( stdout [ 0 ] . includes ( 'Time elapsed:' ) )
103- t . true ( stdout [ 1 ] . includes ( 'Dataset/file is saved in "finance-vix"' ) )
103+ const hasTimeElapsedMsg = stdout . find ( item => item . includes ( 'Time elapsed:' ) )
104+ const hasSuccessMsg = stdout . find ( item => item . includes ( 'Dataset/file is saved in "finance-vix"' ) )
105+ t . truthy ( hasTimeElapsedMsg )
106+ t . truthy ( hasSuccessMsg )
104107} )
105108
106109test ( 'get command with local file' , async t => {
107110 const identifier = 'test/fixtures/sample.csv'
108111 const result = await runcli ( 'get' , identifier )
109112 const stdout = result . stdout . split ( '\n' )
110- t . true ( stdout [ 0 ] . includes ( 'Time elapsed:' ) )
111- t . true ( stdout [ 1 ] . includes ( 'Dataset/file is saved in "sample.csv"' ) )
113+ const hasTimeElapsedMsg = stdout . find ( item => item . includes ( 'Time elapsed:' ) )
114+ const hasSuccessMsg = stdout . find ( item => item . includes ( 'Dataset/file is saved in "sample.csv"' ) )
115+ t . truthy ( hasTimeElapsedMsg )
116+ t . truthy ( hasSuccessMsg )
112117} )
113118
114119// QA tests [Get: Small dataset from DataHub]
@@ -117,9 +122,10 @@ test('get command with small dataset from DataHub', async t => {
117122 const identifier = 'https://datahub.io/test/small-dataset-100kb/'
118123 const result = await runcli ( 'get' , identifier )
119124 const stdout = result . stdout . split ( '\n' )
120- t . true ( stdout [ 0 ] . includes ( 'Time elapsed:' ) )
121- t . true ( stdout [ 1 ] . includes ( 'Dataset/file is saved in "test/small-dataset-100kb"' ) )
122- // t.true(fs.)
125+ const hasTimeElapsedMsg = stdout . find ( item => item . includes ( 'Time elapsed:' ) )
126+ const hasSuccessMsg = stdout . find ( item => item . includes ( 'Dataset/file is saved in "test/small-dataset-100kb"' ) )
127+ t . truthy ( hasTimeElapsedMsg )
128+ t . truthy ( hasSuccessMsg )
123129} )
124130
125131// end of [Get: Small dataset from DataHub]
@@ -130,8 +136,10 @@ test('get command with medium dataset from DataHub', async t => {
130136 const identifier = 'https://datahub.io/test/medium-dataset-1mb'
131137 const result = await runcli ( 'get' , identifier )
132138 const stdout = result . stdout . split ( '\n' )
133- t . true ( stdout [ 0 ] . includes ( 'Time elapsed:' ) )
134- t . true ( stdout [ 1 ] . includes ( 'Dataset/file is saved in "test/medium-dataset-1mb"' ) )
139+ const hasTimeElapsedMsg = stdout . find ( item => item . includes ( 'Time elapsed:' ) )
140+ const hasSuccessMsg = stdout . find ( item => item . includes ( 'Dataset/file is saved in "test/medium-dataset-1mb"' ) )
141+ t . truthy ( hasTimeElapsedMsg )
142+ t . truthy ( hasSuccessMsg )
135143} )
136144
137145// end of [Get: Meduim dataset from DataHub]
@@ -142,8 +150,10 @@ test('get command with big dataset from DataHub', async t => {
142150 const identifier = 'https://datahub.io/test/big-dataset-10mb'
143151 const result = await runcli ( 'get' , identifier )
144152 const stdout = result . stdout . split ( '\n' )
145- t . true ( stdout [ 0 ] . includes ( 'Time elapsed:' ) )
146- t . true ( stdout [ 1 ] . includes ( 'Dataset/file is saved in "test/big-dataset-10mb"' ) )
153+ const hasTimeElapsedMsg = stdout . find ( item => item . includes ( 'Time elapsed:' ) )
154+ const hasSuccessMsg = stdout . find ( item => item . includes ( 'Dataset/file is saved in "test/big-dataset-10mb"' ) )
155+ t . truthy ( hasTimeElapsedMsg )
156+ t . truthy ( hasSuccessMsg )
147157} )
148158
149159// end of [Get: Big dataset from DataHub]
@@ -154,8 +164,10 @@ test('get command with excel file', async t => {
154164 const identifier = 'https://github.com/frictionlessdata/test-data/blob/master/files/excel/sample-1-sheet.xls'
155165 const result = await runcli ( 'get' , identifier )
156166 const stdout = result . stdout . split ( '\n' )
157- t . true ( stdout [ 0 ] . includes ( 'Time elapsed:' ) )
158- t . true ( stdout [ 1 ] . includes ( 'Dataset/file is saved in "sample-1-sheet.xls"' ) )
167+ const hasTimeElapsedMsg = stdout . find ( item => item . includes ( 'Time elapsed:' ) )
168+ const hasSuccessMsg = stdout . find ( item => item . includes ( 'Dataset/file is saved in "sample-1-sheet.xls"' ) )
169+ t . truthy ( hasTimeElapsedMsg )
170+ t . truthy ( hasSuccessMsg )
159171} )
160172
161173// end of [Get: get excel file]
@@ -169,13 +181,14 @@ test('get command with private dataset', async t => {
169181 const token = 'non-owner-token'
170182 let result = await runcli ( 'get' , identifier , `--token=${ token } ` )
171183 let stdout = result . stdout . split ( '\n' )
172- t . true ( stdout [ 0 ] . includes ( '> Error! 404: Not Found. Requested URL' ) )
184+ const hasErrorMsg = stdout . find ( item => item . includes ( '> Error! 404: Not Found. Requested URL' ) )
185+ t . truthy ( hasErrorMsg )
173186
174187 // Now use correct token from env var:
175188 result = await runcli ( 'get' , identifier )
176189 stdout = result . stdout . split ( '\n' )
177- t . true ( stdout [ 0 ] . includes ( 'Time elapsed:' ) )
178- t . true ( stdout [ 1 ] . includes ( 'Dataset/file is saved in "test/private-cli-test"' ) )
190+ const hasTimeElapsedMsg = stdout . find ( item => item . includes ( 'Time elapsed:' ) )
191+ t . truthy ( hasTimeElapsedMsg )
179192 t . true ( fs . existsSync ( 'test/private-cli-test/datapackage.json' ) )
180193} )
181194
@@ -198,14 +211,18 @@ test('Info: basic dataset', async t => {
198211 let identifier = 'test/fixtures/test-data/packages/basic-csv'
199212 let result = await runcli ( 'info' , identifier )
200213 let stdout = result . stdout . split ( '\n' )
201- t . true ( stdout [ 0 ] . includes ( '# basic-csv' ) )
202- t . true ( stdout [ 9 ] . includes ( 'comma-separated' ) )
214+ let hasMsg = stdout . find ( item => item . includes ( '# basic-csv' ) )
215+ t . truthy ( hasMsg )
216+ hasMsg = stdout . find ( item => item . includes ( 'comma-separated' ) )
217+ t . truthy ( hasMsg )
203218
204219 identifier = 'https://github.com/frictionlessdata/test-data/tree/master/packages/basic-csv'
205220 result = await runcli ( 'info' , identifier )
206221 stdout = result . stdout . split ( '\n' )
207- t . true ( stdout [ 0 ] . includes ( '# basic-csv' ) )
208- t . true ( stdout [ 9 ] . includes ( 'comma-separated' ) )
222+ hasMsg = stdout . find ( item => item . includes ( '# basic-csv' ) )
223+ t . truthy ( hasMsg )
224+ hasMsg = stdout . find ( item => item . includes ( 'comma-separated' ) )
225+ t . truthy ( hasMsg )
209226} )
210227
211228// end of [Info: basic dataset]
@@ -312,14 +329,16 @@ test('info command - no dataset or descriptor at URL', async t => {
312329 const url_ = 'https://datahub.io'
313330 const result = await runcli ( 'info' , url_ )
314331 const stdout = result . stdout . split ( '\n' )
315- t . true ( stdout [ 0 ] . includes ( 'Expected URL to a dataset or descriptor.' ) )
332+ const hasErrorMsg = stdout . find ( item => item . includes ( 'Expected URL to a dataset or descriptor.' ) )
333+ t . truthy ( hasErrorMsg )
316334} )
317335
318336test ( 'get command - no dataset or descriptor at URL' , async t => {
319337 const url_ = 'https://datahub.io'
320338 const result = await runcli ( 'get' , url_ )
321339 const stdout = result . stdout . split ( '\n' )
322- t . true ( stdout [ 0 ] . includes ( 'Expected URL to a dataset or descriptor.' ) )
340+ const hasErrorMsg = stdout . find ( item => item . includes ( 'Expected URL to a dataset or descriptor.' ) )
341+ t . truthy ( hasErrorMsg )
323342} )
324343
325344// end of [Proper error messages]
@@ -552,36 +571,42 @@ test('cat command - basic behaviour', async t => {
552571 const path_ = 'test/fixtures/test-data/files/csv/all-schema-types.csv'
553572 const results = await runcli ( 'cat' , path_ )
554573 const stdout = results . stdout . split ( '\n' )
555- t . true ( stdout [ 3 ] . includes ( '│ 1.0 │' ) )
574+ const hasMsg = stdout . find ( item => item . includes ( '│ 1.0 │' ) )
575+ t . truthy ( hasMsg )
556576} )
557577
558578test ( 'cat command - remote csv file' , async t => {
559579 const url_ = 'https://raw.githubusercontent.com/frictionlessdata/test-data/master/files/csv/all-schema-types.csv'
560580 const results = await runcli ( 'cat' , url_ )
561581 const stdout = results . stdout . split ( '\n' )
562- t . true ( stdout [ 3 ] . includes ( '│ 1.0 │' ) )
582+ const hasMsg = stdout . find ( item => item . includes ( '│ 1.0 │' ) )
583+ t . truthy ( hasMsg )
563584} )
564585
565586test ( 'cat command - remote non tabular file' , async t => {
566587 const url_ = 'https://raw.githubusercontent.com/frictionlessdata/test-data/master/files/other/sample.txt'
567588 const results = await runcli ( 'cat' , url_ )
568589 const stdout = results . stdout . split ( '\n' )
569- t . true ( stdout [ 1 ] . includes ( '> Error! We do not have a parser for that format: txt' ) )
590+ const hasErrorMsg = stdout . find ( item => item . includes ( '> Error! We do not have a parser for that format: txt' ) )
591+ t . truthy ( hasErrorMsg )
570592} )
571593
572594test ( 'cat command - non-existing path' , async t => {
573595 const path_ = 'non/existing/path'
574596 const results = await runcli ( 'cat' , path_ )
575597 const stdout = results . stdout . split ( '\n' )
576- t . true ( stdout [ 0 ] . includes ( '> Error! ENOENT: no such file or directory' ) )
598+ const hasErrorMsg = stdout . find ( item => item . includes ( '> Error! ENOENT: no such file or directory' ) )
599+ t . truthy ( hasErrorMsg )
577600} )
578601
579602test ( 'cat command - URL that returns 404' , async t => {
580603 const url_ = 'https://raw.githubusercontent.com/frictionlessdata/test-data/master/files/other/sampl.csv'
581604 const results = await runcli ( 'cat' , url_ )
582605 const stdout = results . stdout . split ( '\n' )
583- t . is ( stdout [ 0 ] , '> Error! Provided URL is invalid' )
584- t . is ( stdout [ 1 ] , '> Error! 404: Not Found. Requested URL: https://raw.githubusercontent.com/frictionlessdata/test-data/master/files/other/sampl.csv' )
606+ let hasErrorMsg = stdout . find ( item => item . includes ( '> Error! Provided URL is invalid' ) )
607+ t . truthy ( hasErrorMsg )
608+ hasErrorMsg = stdout . find ( item => item . includes ( '> Error! 404: Not Found. Requested URL: https://raw.githubusercontent.com/frictionlessdata/test-data/master/files/other/sampl.csv' ) )
609+ t . truthy ( hasErrorMsg )
585610} )
586611
587612// end of [Cat: basic csv]
@@ -593,27 +618,35 @@ test('cat command - files with different separator', async t => {
593618 let path_ = 'test/fixtures/test-data/files/csv/separators/semicolon.csv'
594619 let results = await runcli ( 'cat' , path_ )
595620 let stdout = results . stdout . split ( '\n' )
596- t . false ( stdout [ 1 ] . includes ( ';' ) )
597- t . true ( stdout [ 1 ] . includes ( 'number' ) )
621+ let delimiterWasntRecognized = stdout . find ( item => item . includes ( ';' ) )
622+ t . falsy ( delimiterWasntRecognized )
623+ let hasCorrectPrint = stdout . find ( item => item . includes ( 'number' ) )
624+ t . truthy ( hasCorrectPrint )
598625
599626 path_ = 'test/fixtures/test-data/files/csv/separators/carets.csv'
600627 results = await runcli ( 'cat' , path_ )
601628 stdout = results . stdout . split ( '\n' )
602- t . false ( stdout [ 1 ] . includes ( '^' ) )
603- t . true ( stdout [ 1 ] . includes ( 'number' ) )
629+ delimiterWasntRecognized = stdout . find ( item => item . includes ( '^' ) )
630+ t . falsy ( delimiterWasntRecognized )
631+ hasCorrectPrint = stdout . find ( item => item . includes ( 'number' ) )
632+ t . truthy ( hasCorrectPrint )
604633
605634 // Remote files:
606635 let url_ = 'https://raw.githubusercontent.com/frictionlessdata/test-data/master/files/csv/separators/semicolon.csv'
607636 results = await runcli ( 'cat' , url_ )
608637 stdout = results . stdout . split ( '\n' )
609- t . false ( stdout [ 1 ] . includes ( ';' ) )
610- t . true ( stdout [ 1 ] . includes ( 'number' ) )
638+ delimiterWasntRecognized = stdout . find ( item => item . includes ( ';' ) )
639+ t . falsy ( delimiterWasntRecognized )
640+ hasCorrectPrint = stdout . find ( item => item . includes ( 'number' ) )
641+ t . truthy ( hasCorrectPrint )
611642
612643 url_ = 'https://raw.githubusercontent.com/frictionlessdata/test-data/master/files/csv/separators/carets.csv'
613644 results = await runcli ( 'cat' , url_ )
614645 stdout = results . stdout . split ( '\n' )
615- t . false ( stdout [ 1 ] . includes ( '^' ) )
616- t . true ( stdout [ 1 ] . includes ( 'number' ) )
646+ delimiterWasntRecognized = stdout . find ( item => item . includes ( '^' ) )
647+ t . falsy ( delimiterWasntRecognized )
648+ hasCorrectPrint = stdout . find ( item => item . includes ( 'number' ) )
649+ t . truthy ( hasCorrectPrint )
617650} )
618651
619652// end of [Cat: different separators]
@@ -624,12 +657,14 @@ test.failing('cat command - different encodings', async t => {
624657 const path_ = 'test/fixtures/test-data/files/csv/encodings/iso8859.csv'
625658 let results = await runcli ( 'cat' , path_ )
626659 let stdout = results . stdout . split ( '\n' )
627- t . true ( stdout [ 3 ] . includes ( 'Réunion' ) )
660+ let hasCorrectPrint = stdout . find ( item => item . includes ( 'Réunion' ) )
661+ t . truthy ( hasCorrectPrint )
628662
629663 const url_ = 'https://raw.githubusercontent.com/frictionlessdata/test-data/master/files/csv/encodings/western-macos-roman.csv'
630664 results = await runcli ( 'cat' , url_ )
631665 stdout = results . stdout . split ( '\n' )
632- t . true ( stdout [ 3 ] . includes ( 'Réunion' ) )
666+ hasCorrectPrint = stdout . find ( item => item . includes ( 'Réunion' ) )
667+ t . truthy ( hasCorrectPrint )
633668} )
634669
635670// end of [Cat: different encodings]
@@ -638,28 +673,32 @@ test('cat command - local tsv file', async t => {
638673 const path_ = 'test/fixtures/test-data/files/csv/separators/tab.tsv'
639674 const results = await runcli ( 'cat' , path_ )
640675 const stdout = results . stdout . split ( '\n' )
641- t . true ( stdout [ 1 ] . includes ( 'number' ) )
676+ const hasCorrectPrint = stdout . find ( item => item . includes ( 'number' ) )
677+ t . truthy ( hasCorrectPrint )
642678} )
643679
644680test ( 'cat command - remote tsv file' , async t => {
645681 const url_ = 'https://raw.githubusercontent.com/frictionlessdata/test-data/master/files/csv/separators/tab.tsv'
646682 const results = await runcli ( 'cat' , url_ )
647683 const stdout = results . stdout . split ( '\n' )
648- t . true ( stdout [ 1 ] . includes ( 'number' ) )
684+ const hasCorrectPrint = stdout . find ( item => item . includes ( 'number' ) )
685+ t . truthy ( hasCorrectPrint )
649686} )
650687
651688test ( 'cat command - inconsistent columns' , async t => {
652689 const path_ = 'test/fixtures/test-data/files/csv/inconsistent-column-number.csv'
653690 const results = await runcli ( 'cat' , path_ )
654691 const stdout = results . stdout . split ( '\n' )
655- t . is ( stdout [ 0 ] , '> Error! Number of columns is inconsistent on line 3' )
692+ const hasErrorMsg = stdout . find ( item => item . includes ( '> Error! Number of columns is inconsistent on line 3' ) )
693+ t . truthy ( hasErrorMsg )
656694} )
657695
658696test ( 'cat command - remote excel file' , async t => {
659697 const url_ = 'https://github.com/frictionlessdata/test-data/raw/master/files/excel/sample-1-sheet.xls'
660698 const results = await runcli ( 'cat' , url_ )
661699 const stdout = results . stdout . split ( '\n' )
662- t . true ( stdout [ 1 ] . includes ( 'number' ) )
700+ const hasCorrectPrint = stdout . find ( item => item . includes ( 'number' ) )
701+ t . truthy ( hasCorrectPrint )
663702} )
664703
665704test ( 'cat command - specific excel sheet' , async t => {
0 commit comments