Skip to content

Commit cc921a4

Browse files
committed
fix:failling test
1 parent c29bdd4 commit cc921a4

File tree

2 files changed

+8
-12
lines changed

2 files changed

+8
-12
lines changed

src/lib/contract/contract-file.es6

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import * as path from 'path';
22
import fs from 'fs';
33
import { 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
}

test/lib/contract/contract-file.test.es6

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import test from 'tape';
22
import fs from 'fs';
3+
import os from 'os';
4+
import path from 'path';
35
import { ContractFile } from '../../../src/lib/contract/contract-file';
46

57
test('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
});

0 commit comments

Comments
 (0)