Skip to content

Commit

Permalink
fix:failling test
Browse files Browse the repository at this point in the history
  • Loading branch information
mpetrunic committed Aug 2, 2022
1 parent c29bdd4 commit cc921a4
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 12 deletions.
12 changes: 2 additions & 10 deletions src/lib/contract/contract-file.es6
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import * as path from 'path';
import fs from 'fs';
import { Contract } from './contract';

export class ContractFile extends Contract{
export class ContractFile extends Contract {

constructor(filePath) {
if (!fs.existsSync(filePath)) {
Expand All @@ -25,15 +25,7 @@ export class ContractFile extends Contract{
if (!path) {
path = this.path;
}
return new Promise((resolve, reject) => {
let file = fs.createWriteStream(path);
file.on('error', function(err) { reject(err); });
this.lines.forEach((line) => {
file.write(line + '\n');
});
file.end();
resolve();
});
fs.writeFileSync(path, this.lines.join('\n'), { encoding: 'utf-8' });
}

}
8 changes: 6 additions & 2 deletions test/lib/contract/contract-file.test.es6
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import test from 'tape';
import fs from 'fs';
import os from 'os';
import path from 'path';
import { ContractFile } from '../../../src/lib/contract/contract-file';

test('Assert not founding contract file', (t) => {
Expand Down Expand Up @@ -35,6 +37,8 @@ test('Save file', async(t) => {
t.plan(1);
let contract = new ContractFile('./test/test-contracts/Metacoin.sol');
contract.insertTextBefore('test1\nbla', 'pragma solidity ^0.4.24;');
await contract.save('/tmp/Metacoin-test.sol');
t.notEqual(fs.readFileSync('/tmp/Metacoin-test.sol'), fs.readFileSync('./test/test-contracts/Metacoin.sol'));
const tmp = fs.mkdtempSync(path.join(os.tmpdir(),"solidity-comments-core"));
const filePath = path.join(tmp,'Metacoin-test.sol');
await contract.save(filePath);
t.notEqual(fs.readFileSync(filePath), fs.readFileSync('./test/test-contracts/Metacoin.sol'));
});

0 comments on commit cc921a4

Please sign in to comment.