|
| 1 | +var func = require('./' + global.tests_dir +'/start_app/script.js'); |
| 2 | +var execPath = func.getExecPath(); |
| 3 | +var fs = require('fs-extra'); |
| 4 | +var os = require('os'); |
| 5 | +var cp = require('child_process'); |
| 6 | +var app_test = require('./nw_test_app'); |
| 7 | +var current_path = process.cwd(); |
| 8 | +var mac_app_path = path.join('tmp-nw', 'node-webkit.app'); |
| 9 | +var assert = require('assert'); |
| 10 | +var temp_path; |
| 11 | +var execPath; |
| 12 | + |
| 13 | +if (os.platform() == 'win32') { |
| 14 | + execPath = path.join('tmp-nw', 'app.exe'); |
| 15 | +} |
| 16 | +if (os.platform() == 'linux') { |
| 17 | + execPath = path.join('tmp-nw', 'app'); |
| 18 | +} |
| 19 | +if (os.platform() == 'darwin') { |
| 20 | + execPath = path.join('tmp-nw', 'node-webkit.app', 'Contents', 'MacOS', 'node-webkit'); |
| 21 | +} |
| 22 | + |
| 23 | +function make_execuable_file(folder_path, done) { |
| 24 | + func.copyExecFiles(function() { |
| 25 | + func.copySourceFiles(folder_path); |
| 26 | + func.zipSourceFiles(function() { |
| 27 | + func.makeExecuableFile(); |
| 28 | + if (os.platform() == 'darwin') { |
| 29 | + var app_path = 'tmp-nw/node-webkit.app/Contents/Resources/app.nw'; |
| 30 | + fs.mkdir(app_path, function(err) { |
| 31 | + if(err && err.code !== 'EEXIST') throw err |
| 32 | + fs.copy('tmp-nw/index.html', path.join(app_path, 'index.html')); |
| 33 | + fs.copy('tmp-nw/package.html', path.join(app_path, 'package.html')); |
| 34 | + setTimeout(done, 3000); |
| 35 | + |
| 36 | + }); |
| 37 | + } else { |
| 38 | + setTimeout(function() { |
| 39 | + var child = cp.spawn(execPath, [current_path]); |
| 40 | + child.on('exit', function() { |
| 41 | + temp_path = path.dirname(fs.readFileSync(path.join('tmp-nw','path.org'))).substring(8); |
| 42 | + done(); |
| 43 | + }); |
| 44 | + }, 3000); |
| 45 | + } |
| 46 | + }); |
| 47 | + }); |
| 48 | +} |
| 49 | + |
| 50 | +describe('temp_dir', function() { |
| 51 | + this.timeout(0); |
| 52 | + |
| 53 | + before(function(done) { |
| 54 | + make_execuable_file('temp_dir', done); |
| 55 | + }); |
| 56 | + |
| 57 | + after(function() { |
| 58 | + fs.remove('tmp-nw', function (er) { |
| 59 | + if (er) throw er; |
| 60 | + }); |
| 61 | + }); |
| 62 | + |
| 63 | + it('should be removed after app exit', function() { |
| 64 | + var exist = fs.existsSync(temp_path); |
| 65 | + assert.equal(exist, false); |
| 66 | + }); |
| 67 | +}); |
0 commit comments