File tree Expand file tree Collapse file tree 2 files changed +8
-12
lines changed
Expand file tree Collapse file tree 2 files changed +8
-12
lines changed Original file line number Diff line number Diff line change @@ -2,7 +2,7 @@ import * as path from 'path';
22import fs from 'fs' ;
33import { Contract } from './contract' ;
44
5- export class ContractFile extends Contract {
5+ export class ContractFile extends Contract {
66
77 constructor ( filePath ) {
88 if ( ! fs . existsSync ( filePath ) ) {
@@ -25,15 +25,7 @@ export class ContractFile extends Contract{
2525 if ( ! path ) {
2626 path = this . path ;
2727 }
28- return new Promise ( ( resolve , reject ) => {
29- let file = fs . createWriteStream ( path ) ;
30- file . on ( 'error' , function ( err ) { reject ( err ) ; } ) ;
31- this . lines . forEach ( ( line ) => {
32- file . write ( line + '\n' ) ;
33- } ) ;
34- file . end ( ) ;
35- resolve ( ) ;
36- } ) ;
28+ fs . writeFileSync ( path , this . lines . join ( '\n' ) , { encoding : 'utf-8' } ) ;
3729 }
3830
3931}
Original file line number Diff line number Diff line change 11import test from 'tape' ;
22import fs from 'fs' ;
3+ import os from 'os' ;
4+ import path from 'path' ;
35import { ContractFile } from '../../../src/lib/contract/contract-file' ;
46
57test ( 'Assert not founding contract file' , ( t ) => {
@@ -35,6 +37,8 @@ test('Save file', async(t) => {
3537 t . plan ( 1 ) ;
3638 let contract = new ContractFile ( './test/test-contracts/Metacoin.sol' ) ;
3739 contract . insertTextBefore ( 'test1\nbla' , 'pragma solidity ^0.4.24;' ) ;
38- await contract . save ( '/tmp/Metacoin-test.sol' ) ;
39- t . notEqual ( fs . readFileSync ( '/tmp/Metacoin-test.sol' ) , fs . readFileSync ( './test/test-contracts/Metacoin.sol' ) ) ;
40+ const tmp = fs . mkdtempSync ( path . join ( os . tmpdir ( ) , "solidity-comments-core" ) ) ;
41+ const filePath = path . join ( tmp , 'Metacoin-test.sol' ) ;
42+ await contract . save ( filePath ) ;
43+ t . notEqual ( fs . readFileSync ( filePath ) , fs . readFileSync ( './test/test-contracts/Metacoin.sol' ) ) ;
4044} ) ;
You can’t perform that action at this time.
0 commit comments