1- import { expect } from "chai" ;
2- import * as path from "path" ;
3- import { ArchiveFileSystemProvider , decodeSourceArchiveUri , encodeSourceArchiveUri , ZipFileReference } from "../../archive-filesystem-provider" ;
1+ import { expect } from 'chai' ;
2+ import * as path from 'path' ;
43
5- describe ( "archive filesystem provider" , ( ) => {
4+ import { encodeSourceArchiveUri , ArchiveFileSystemProvider , decodeSourceArchiveUri , ZipFileReference } from '../../archive-filesystem-provider' ;
5+ import { FileType , FileSystemError } from 'vscode' ;
6+
7+ describe ( 'archive-filesystem-provider' , ( ) => {
68 it ( "reads empty file correctly" , async ( ) => {
79 const archiveProvider = new ArchiveFileSystemProvider ( ) ;
810 const uri = encodeSourceArchiveUri ( {
@@ -12,6 +14,98 @@ describe("archive filesystem provider", () => {
1214 const data = await archiveProvider . readFile ( uri ) ;
1315 expect ( data . length ) . to . equal ( 0 ) ;
1416 } ) ;
17+
18+ it ( "read non-empty file correctly" , async ( ) => {
19+ const archiveProvider = new ArchiveFileSystemProvider ( ) ;
20+ const uri = encodeSourceArchiveUri ( {
21+ sourceArchiveZipPath : path . resolve ( __dirname , "data/archive-filesystem-provider-test/zip_with_folder.zip" ) ,
22+ pathWithinSourceArchive : "folder1/textFile.txt"
23+ } ) ;
24+ const data = await archiveProvider . readFile ( uri ) ;
25+ expect ( Buffer . from ( data ) . toString ( 'utf8' ) ) . to . be . equal ( 'I am a text\n' ) ;
26+ } ) ;
27+
28+ it ( "read a directory" , async ( ) => {
29+ const archiveProvider = new ArchiveFileSystemProvider ( ) ;
30+ const uri = encodeSourceArchiveUri ( {
31+ sourceArchiveZipPath : path . resolve ( __dirname , "data/archive-filesystem-provider-test/zip_with_folder.zip" ) ,
32+ pathWithinSourceArchive : "folder1"
33+ } ) ;
34+ const files = await archiveProvider . readDirectory ( uri ) ;
35+ expect ( files ) . to . be . deep . equal ( [
36+ [ 'folder2' , FileType . Directory ] ,
37+ [ 'textFile.txt' , FileType . File ] ,
38+ [ 'textFile2.txt' , FileType . File ] ,
39+ ] ) ;
40+ } ) ;
41+
42+ it ( 'should handle a missing directory' , async ( ) => {
43+ const archiveProvider = new ArchiveFileSystemProvider ( ) ;
44+ const uri = encodeSourceArchiveUri ( {
45+ sourceArchiveZipPath : path . resolve ( __dirname , "data/archive-filesystem-provider-test/zip_with_folder.zip" ) ,
46+ pathWithinSourceArchive : "folder1/not-here"
47+ } ) ;
48+ try {
49+ await archiveProvider . readDirectory ( uri ) ;
50+ throw new Error ( 'Failed' ) ;
51+ } catch ( e ) {
52+ expect ( e ) . to . be . instanceOf ( FileSystemError ) ;
53+ }
54+ } ) ;
55+
56+ it ( 'should handle a missing file' , async ( ) => {
57+ const archiveProvider = new ArchiveFileSystemProvider ( ) ;
58+ const uri = encodeSourceArchiveUri ( {
59+ sourceArchiveZipPath : path . resolve ( __dirname , "data/archive-filesystem-provider-test/zip_with_folder.zip" ) ,
60+ pathWithinSourceArchive : "folder1/not-here"
61+ } ) ;
62+ try {
63+ await archiveProvider . readFile ( uri ) ;
64+ throw new Error ( 'Failed' ) ;
65+ } catch ( e ) {
66+ expect ( e ) . to . be . instanceOf ( FileSystemError ) ;
67+ }
68+ } ) ;
69+
70+ it ( 'should handle reading a file as a directory' , async ( ) => {
71+ const archiveProvider = new ArchiveFileSystemProvider ( ) ;
72+ const uri = encodeSourceArchiveUri ( {
73+ sourceArchiveZipPath : path . resolve ( __dirname , "data/archive-filesystem-provider-test/zip_with_folder.zip" ) ,
74+ pathWithinSourceArchive : "folder1/textFile.txt"
75+ } ) ;
76+ try {
77+ await archiveProvider . readDirectory ( uri ) ;
78+ throw new Error ( 'Failed' ) ;
79+ } catch ( e ) {
80+ expect ( e ) . to . be . instanceOf ( FileSystemError ) ;
81+ }
82+ } ) ;
83+
84+ it ( 'should handle reading a directory as a file' , async ( ) => {
85+ const archiveProvider = new ArchiveFileSystemProvider ( ) ;
86+ const uri = encodeSourceArchiveUri ( {
87+ sourceArchiveZipPath : path . resolve ( __dirname , "data/archive-filesystem-provider-test/zip_with_folder.zip" ) ,
88+ pathWithinSourceArchive : "folder1/folder2"
89+ } ) ;
90+ try {
91+ await archiveProvider . readFile ( uri ) ;
92+ throw new Error ( 'Failed' ) ;
93+ } catch ( e ) {
94+ expect ( e ) . to . be . instanceOf ( FileSystemError ) ;
95+ }
96+ } ) ;
97+
98+ it ( "read a nested directory" , async ( ) => {
99+ const archiveProvider = new ArchiveFileSystemProvider ( ) ;
100+ const uri = encodeSourceArchiveUri ( {
101+ sourceArchiveZipPath : path . resolve ( __dirname , "data/archive-filesystem-provider-test/zip_with_folder.zip" ) ,
102+ pathWithinSourceArchive : "folder1/folder2"
103+ } ) ;
104+ const files = await archiveProvider . readDirectory ( uri ) ;
105+ expect ( files ) . to . be . deep . equal ( [
106+ [ 'textFile3.txt' , FileType . File ] ,
107+ ] ) ;
108+ } ) ;
15109} ) ;
16110
17111describe ( 'source archive uri encoding' , function ( ) {
0 commit comments