-
-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
113 additions
and
113 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,46 +1,43 @@ | ||
var Zip = require('nativescript-zip').Zip; | ||
var fs = require('tns-core-modules/file-system'); | ||
var testData = 'Testing testing 123'; | ||
var testPath = function () { | ||
const Zip = require('nativescript-zip').Zip; | ||
const fs = require('tns-core-modules/file-system'); | ||
const testData = 'Testing testing 123'; | ||
const testPath = function () { | ||
return fs.path.join(fs.knownFolders.documents().path, 'zip_test'); | ||
}; | ||
var testFile = `${Date.now()}.txt`; | ||
var output; | ||
const testFile = `${Date.now()}.txt`; | ||
let output; | ||
describe('Zip functions', function () { | ||
it('creates a file then add file to zip', function () { | ||
const testFilePath = fs.path.join(testPath(), testFile); | ||
fs.File.fromPath(testFilePath).writeTextSync(testData, function (error) { | ||
fail(error); | ||
}); | ||
return Zip.zip({ | ||
directory: testPath(), | ||
}) | ||
.then(function (archive) { | ||
output = archive; | ||
expect(archive).toBeDefined(); | ||
expect(fs.File.exists(archive)).toBe(true); | ||
expect(fs.File.fromPath(archive).size).toBeGreaterThan(0); | ||
}).catch(function (error) { | ||
fail(error); | ||
it('creates a file then add file to zip', async function () { | ||
try { | ||
const testFilePath = fs.path.join(testPath(), testFile); | ||
await fs.File.fromPath(testFilePath).writeText(testData); | ||
const archive = await Zip.zip({ | ||
directory: testPath(), | ||
}); | ||
|
||
output = archive; | ||
expect(archive).toBeDefined(); | ||
expect(fs.File.exists(archive)).toBe(true); | ||
expect(fs.File.fromPath(archive).size).toBeGreaterThan(0); | ||
} catch (error) { | ||
fail(error); | ||
} | ||
}); | ||
|
||
it('extract zip then reads file created earlier', function () { | ||
expect(output).toBeDefined(); | ||
return Zip.unzip({ | ||
archive: output | ||
}) | ||
.then(function (path) { | ||
expect(path).toBeDefined(); | ||
expect(fs.Folder.exists(path)).toBe(true); | ||
var file = fs.path.join(path, 'zip_test', testFile); | ||
var text = fs.File.fromPath(file).readTextSync(function (error) { | ||
fail(error); | ||
}); | ||
expect(text).toEqual(testData); | ||
}).catch(function (error) { | ||
fail(error); | ||
}) | ||
it('extract zip then reads file created earlier', async function () { | ||
try { | ||
expect(output).toBeDefined(); | ||
const path = await Zip.unzip({ | ||
archive: output | ||
}); | ||
expect(path).toBeDefined(); | ||
expect(fs.Folder.exists(path)).toBe(true); | ||
const file = fs.path.join(path, 'zip_test', testFile); | ||
const text = await fs.File.fromPath(file).readText(); | ||
expect(text).toEqual(testData); | ||
} catch (error) { | ||
fail(error); | ||
} | ||
}); | ||
|
||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,109 +1,112 @@ | ||
module.exports = function (config) { | ||
const options = { | ||
const options = { | ||
|
||
// base path that will be used to resolve all patterns (eg. files, exclude) | ||
basePath: '', | ||
// base path that will be used to resolve all patterns (eg. files, exclude) | ||
basePath: '', | ||
|
||
|
||
// frameworks to use | ||
// available frameworks: https://npmjs.org/browse/keyword/karma-adapter | ||
frameworks: ['jasmine'], | ||
// frameworks to use | ||
// available frameworks: https://npmjs.org/browse/keyword/karma-adapter | ||
frameworks: ['jasmine'], | ||
|
||
|
||
// list of files / patterns to load in the browser | ||
files: ['app/tests/**/*.*'], | ||
// list of files / patterns to load in the browser | ||
files: ['app/tests/**/*.*'], | ||
|
||
|
||
// list of files to exclude | ||
exclude: [ | ||
], | ||
// list of files to exclude | ||
exclude: [], | ||
|
||
|
||
// preprocess matching files before serving them to the browser | ||
// available preprocessors: https://npmjs.org/browse/keyword/karma-preprocessor | ||
preprocessors: { | ||
}, | ||
// preprocess matching files before serving them to the browser | ||
// available preprocessors: https://npmjs.org/browse/keyword/karma-preprocessor | ||
preprocessors: {}, | ||
|
||
|
||
// test results reporter to use | ||
// possible values: 'dots', 'progress' | ||
// available reporters: https://npmjs.org/browse/keyword/karma-reporter | ||
reporters: ['progress'], | ||
// test results reporter to use | ||
// possible values: 'dots', 'progress' | ||
// available reporters: https://npmjs.org/browse/keyword/karma-reporter | ||
reporters: ['progress'], | ||
|
||
|
||
// web server port | ||
port: 9876, | ||
// web server port | ||
port: 9876, | ||
|
||
|
||
// enable / disable colors in the output (reporters and logs) | ||
colors: true, | ||
// enable / disable colors in the output (reporters and logs) | ||
colors: true, | ||
|
||
|
||
// level of logging | ||
// possible values: config.LOG_DISABLE || config.LOG_ERROR || config.LOG_WARN || config.LOG_INFO || config.LOG_DEBUG | ||
logLevel: config.LOG_INFO, | ||
// level of logging | ||
// possible values: config.LOG_DISABLE || config.LOG_ERROR || config.LOG_WARN || config.LOG_INFO || config.LOG_DEBUG | ||
logLevel: config.LOG_INFO, | ||
|
||
|
||
// enable / disable watching file and executing tests whenever any file changes | ||
autoWatch: true, | ||
// enable / disable watching file and executing tests whenever any file changes | ||
autoWatch: true, | ||
|
||
|
||
// start these browsers | ||
// available browser launchers: https://npmjs.org/browse/keyword/karma-launcher | ||
browsers: [], | ||
// start these browsers | ||
// available browser launchers: https://npmjs.org/browse/keyword/karma-launcher | ||
browsers: [], | ||
|
||
customLaunchers: { | ||
android: { | ||
base: 'NS', | ||
platform: 'android' | ||
}, | ||
ios: { | ||
base: 'NS', | ||
platform: 'ios' | ||
}, | ||
ios_simulator: { | ||
base: 'NS', | ||
platform: 'ios', | ||
arguments: ['--emulator'] | ||
} | ||
}, | ||
customLaunchers: { | ||
android: { | ||
base: 'NS', | ||
platform: 'android' | ||
}, | ||
ios: { | ||
base: 'NS', | ||
platform: 'ios' | ||
}, | ||
ios_simulator: { | ||
base: 'NS', | ||
platform: 'ios', | ||
arguments: ['--emulator'] | ||
} | ||
}, | ||
client: { | ||
jasmine: { | ||
random: false, | ||
} | ||
}, | ||
|
||
// Continuous Integration mode | ||
// if true, Karma captures browsers, runs the tests and exits | ||
singleRun: false | ||
}; | ||
// Continuous Integration mode | ||
// if true, Karma captures browsers, runs the tests and exits | ||
singleRun: false | ||
}; | ||
|
||
setWebpackPreprocessor(config, options); | ||
setWebpack(config, options); | ||
setWebpackPreprocessor(config, options); | ||
setWebpack(config, options); | ||
|
||
config.set(options); | ||
config.set(options); | ||
} | ||
|
||
function setWebpackPreprocessor(config, options) { | ||
if (config && config.bundle) { | ||
if (!options.preprocessors) { | ||
options.preprocessors = {}; | ||
} | ||
|
||
options.files.forEach(file => { | ||
if (!options.preprocessors[file]) { | ||
options.preprocessors[file] = []; | ||
} | ||
options.preprocessors[file].push('webpack'); | ||
}); | ||
} | ||
if (config && config.bundle) { | ||
if (!options.preprocessors) { | ||
options.preprocessors = {}; | ||
} | ||
|
||
options.files.forEach(file => { | ||
if (!options.preprocessors[ file ]) { | ||
options.preprocessors[ file ] = []; | ||
} | ||
options.preprocessors[ file ].push('webpack'); | ||
}); | ||
} | ||
} | ||
|
||
function setWebpack(config, options) { | ||
if (config && config.bundle) { | ||
const env = {}; | ||
env[config.platform] = true; | ||
env.sourceMap = config.debugBrk; | ||
env.appPath = config.appPath; | ||
options.webpack = require('./webpack.config')(env); | ||
delete options.webpack.entry; | ||
delete options.webpack.output.libraryTarget; | ||
const invalidPluginsForUnitTesting = ["GenerateBundleStarterPlugin", "GenerateNativeScriptEntryPointsPlugin"]; | ||
options.webpack.plugins = options.webpack.plugins.filter(p => !invalidPluginsForUnitTesting.includes(p.constructor.name)); | ||
} | ||
if (config && config.bundle) { | ||
const env = {}; | ||
env[ config.platform ] = true; | ||
env.sourceMap = config.debugBrk; | ||
env.appPath = config.appPath; | ||
options.webpack = require('./webpack.config')(env); | ||
delete options.webpack.entry; | ||
delete options.webpack.output.libraryTarget; | ||
const invalidPluginsForUnitTesting = ['GenerateBundleStarterPlugin', 'GenerateNativeScriptEntryPointsPlugin']; | ||
options.webpack.plugins = options.webpack.plugins.filter(p => !invalidPluginsForUnitTesting.includes(p.constructor.name)); | ||
} | ||
} |