#!/usr/bin/env node

const fs = require('fs')
const test = require('tape')
const basePath = `${process.cwd()}/test/fixtures`
const chalk = require('chalk')

function compareCritical (t, name, testNonCritical) {
  t.equal(
    fs.readFileSync(
`${basePath}/${name}.${testNonCritical ? 'non-critical.actual' : 'critical.actual'}.css`, 'utf8'
    ).trim(),
    fs.readFileSync(
`${basePath}/${name}.${testNonCritical ? 'non-critical.expected' : 'critical.expected'}.css`, 'utf8'
    ).trim(),
    `processed fixture ${chalk.bold(name)} should be equal to expected output`
  )
}

test('Testing "this" critical result', function (t) {
  compareCritical(t, 'this')
  t.end()
})

test('Testing "this" non-critical result', function (t) {
  compareCritical(t, 'this', true)
  t.end()
})

test('Testing "atRule" critical result', function (t) {
  compareCritical(t, 'atRule')
  t.end()
})

test('Testing "atRule" non-critical result', function (t) {
  compareCritical(t, 'atRule', true)
  t.end()
})

test(chalk.yellow(`Testing ${chalk.bold('atRule.wrapping')} critical result`), function (t) {
  compareCritical(t, 'atRule-wrapping')
  t.end()
})

test(chalk.yellow(`Testing ${chalk.bold('atRule.wrapping')} non-critical result`), function (t) {
  compareCritical(t, 'atRule-wrapping', true)
  t.end()
})

test('Testing "media" critical result', function (t) {
  compareCritical(t, 'media')
  t.end()
})

test('Testing "media" non-critical result', function (t) {
  compareCritical(t, 'media', true)
  t.end()
})

test(chalk.yellow(`Testing ${chalk.bold('scope')} critical result`), function (t) {
  compareCritical(t, 'scope')
  t.end()
})

test(chalk.yellow(`Testing ${chalk.bold('scope')} non-critical result`), function (t) {
  compareCritical(t, 'scope', true)
  t.end()
})

@@ -604,36 +604,30 @@
 al result', 
-function 
 (t)
+ =%3E
  %7B%0A  compare
@@ -699,36 +699,30 @@
 al result', 
-function 
 (t)
+ =%3E
  %7B%0A  compare
@@ -798,36 +798,30 @@
 al result', 
-function 
 (t)
+ =%3E
  %7B%0A  compare
@@ -897,36 +897,30 @@
 al result', 
-function 
 (t)
+ =%3E
  %7B%0A  compare
@@ -1036,36 +1036,30 @@
 l result%60), 
-function 
 (t)
+ =%3E
  %7B%0A  compare
@@ -1182,36 +1182,30 @@
 l result%60), 
-function 
 (t)
+ =%3E
  %7B%0A  compare
@@ -1291,36 +1291,30 @@
 al result', 
-function 
 (t)
+ =%3E
  %7B%0A  compare
@@ -1391,29 +1391,23 @@
 result',
- function
  (t)
+ =%3E
  %7B%0A  com
@@ -1515,37 +1515,31 @@
 al result%60),
- function
  (t)
+ =%3E
  %7B%0A  compare
@@ -1650,20 +1650,14 @@
 %60), 
-function 
 (t)
+ =%3E
  %7B%0A 

use arrow functions in test index.js