<commit_before>package io.scalajs.nodejs.fs

import io.scalajs.nodejs.setImmediate
import io.scalajs.nodejs.util.Util
import org.scalatest.FunSpec

import scala.scalajs.js

/**
  * File System (Fs) Tests
  * @author <EMAIL>
  */
class FsTest extends FunSpec {

  describe("Fs") {

    it("supports watching files") {
      val watcher = Fs.watch("./src/test/resources/", (value: js.Any) => {
        info(s"watcher value: ${Util.inspect(value)}")
      })
      info(s"watcher: ${Util.inspect(watcher)}")

      setImmediate(() => Fs.writeFile("./src/test/resources/1.txt", "Hello", () => {}))
    }

    it("should stream data") {
      val file1 = "./src/test/resources/fileA1.txt"
      val file2 = "./src/test/resources/fileA2.txt"
      val file3 = "./src/test/resources/fileC2.txt"

      val readable = Fs.createReadStream(file1)
      val writable = Fs.createWriteStream(file2)
      readable.setEncoding("utf8")
      readable.onData(chunk => writable.write(chunk))
      writable.onFinish { () =>
        info("Comparing file sizes:")
        info(s"$file1 is ${Fs.statSync(file1).size} bytes")
        info(s"$file2 is ${Fs.statSync(file2).size} bytes")
        assert(Fs.statSync(file1).size == Fs.statSync(file2).size)

        info("should rename the file")
        Fs.renameSync(file2, file3)
        assert(Fs.statSync(file2).isFile())

        info("should delete the file")
        Fs.unlinkSync(file3)
        val deleted = !Fs.existsSync(file3)
        info(s"deleted? $deleted")
        assert(deleted)
      }
    }

    it("should pipe data from a Readable to a Writable") {
      val file1 = "./src/test/resources/fileB1.txt"
      val file2 = "./src/test/resources/fileB2.txt"

      val readable = Fs.createReadStream(file1)
      val writable = Fs.createWriteStream(file2)
      readable.pipe(writable)
      writable.onFinish { () =>
        info("Comparing file sizes:")
        info(s"$file1 is ${Fs.statSync(file1).size} bytes")
        info(s"$file2 is ${Fs.statSync(file2).size} bytes")
        assert(Fs.statSync(file1).size == Fs.statSync(file2).size)
      }
    }

  }

}
<commit_msg>Test fixes<commit_after>package io.scalajs.nodejs.fs

import io.scalajs.JSON
import io.scalajs.nodejs.setImmediate
import io.scalajs.nodejs.util.Util
import io.scalajs.util.ScalaJsHelper._
import org.scalatest.FunSpec

import scala.scalajs.js

/**
  * File System (Fs) Tests
  * @author <EMAIL>
  */
class FsTest extends FunSpec {

  describe("Fs") {

    it("supports watching files") {
      val watcher = Fs.watch("./src/test/resources/", (eventType, file) => {
        info(s"watcher: eventType = '$eventType' file = '$file'")
      })
      info(s"watcher: ${Util.inspect(watcher)}")

      setImmediate(() => Fs.writeFile("./src/test/resources/1.txt", "Hello", error => {
        if (isDefined(error)) {
          alert(s"error: ${JSON.stringify(error)}")
        }
      }))
    }

    it("should stream data") {
      val file1 = "./src/test/resources/fileA1.txt"
      val file2 = "./src/test/resources/fileA2.txt"
      val file3 = "./src/test/resources/fileC2.txt"

      val readable = Fs.createReadStream(file1)
      val writable = Fs.createWriteStream(file2)
      readable.setEncoding("utf8")
      readable.onData[String](chunk => writable.write(chunk))
      writable.onFinish { () =>
        info("Comparing file sizes:")
        info(s"$file1 is ${Fs.statSync(file1).size} bytes")
        info(s"$file2 is ${Fs.statSync(file2).size} bytes")
        assert(Fs.statSync(file1).size == Fs.statSync(file2).size)

        info("should rename the file")
        Fs.renameSync(file2, file3)
        assert(Fs.statSync(file2).isFile())

        info("should delete the file")
        Fs.unlinkSync(file3)
        val deleted = !Fs.existsSync(file3)
        info(s"deleted? $deleted")
        assert(deleted)
      }
    }

    it("should pipe data from a Readable to a Writable") {
      val file1 = "./src/test/resources/fileB1.txt"
      val file2 = "./src/test/resources/fileB2.txt"

      val readable = Fs.createReadStream(file1)
      val writable = Fs.createWriteStream(file2)
      readable.pipe(writable)
      writable.onFinish { () =>
        info("Comparing file sizes:")
        info(s"$file1 is ${Fs.statSync(file1).size} bytes")
        info(s"$file2 is ${Fs.statSync(file2).size} bytes")
        assert(Fs.statSync(file1).size == Fs.statSync(file2).size)
      }
    }

  }

}

{'fraction_non_alphanumeric': 0.15589697243560777, 'fraction_numerical': 0.0149118843199277, 'mean_word_length': 2.732715008431703, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4503289', 'n_tokens_mistral': 1582, 'n_tokens_neox': 1523, 'n_words': 264}