<commit_before>
import test from 'ava'
import hash from 'murmurhash-js/murmurhash3_gc'
import prefixer from 'inline-style-prefixer/static'
import jsdom from 'jsdom-global'
import cxs, { cache, styleId } from '../src'

jsdom('<html></html>')

const style = {
  color: 'tomato',
  display: 'flex',
  fontSize: 32
}

test.beforeEach(() => {
  cxs.clearCache()
})

test('does not throw', t => {
  t.notThrows(() => {
    cxs(style)
  })
})

test('returns a classname', t => {
  const cx = cxs(style)
  t.is(typeof cx, 'string')
})

test('returns a consistent hashed classname', t => {
  const hashname = hash(JSON.stringify(style), 128)
  const cx = cxs(style)
  t.is(cx, `cxs-${hashname}`)
})

test('attaches a style tag and CSSStyleSheet', async t => {
  t.plan(1)
  cxs.attach()
  const getTag = () => {
    return new Promise((resolve, reject) => {
      setTimeout(() => {
        const tag = document.getElementById(styleId)
        resolve(tag.tagName)
      }, 200)
    })
  }
  // Travis error with CSSStyleSheet is undefined
  // t.true(cxs.sheet instanceof CSSStyleSheet)
  t.is(await getTag(), 'STYLE')
})

test('Adds px unit to number values', t => {
  const sx = {
    fontSize: 32
  }
  cxs(sx)
  const rules = cxs.rules
  t.regex(rules[0].css, /font-size:32px}$/)
})

test('creates pseudoclass rules', t => {
  t.plan(2)<commit_msg>Double double check classname test for @kristoferjoseph<commit_after>
import test from 'ava'
import hash from 'murmurhash-js/murmurhash3_gc'
import prefixer from 'inline-style-prefixer/static'
import jsdom from 'jsdom-global'
import cxs, { cache, styleId } from '../src'

jsdom('<html></html>')

const style = {
  color: 'tomato',
  display: 'flex',
  fontSize: 32
}

test.beforeEach(() => {
  cxs.clearCache()
})

test('does not throw', t => {
  t.notThrows(() => {
    cxs(style)
  })
})

test('returns a classname', t => {
  const cx = cxs(style)
  t.is(typeof cx, 'string')
})

test('returns a consistent hashed classname', t => {
  t.plan(2)
  const hashname = hash(JSON.stringify(style), 128)
  const cx = cxs(style)
  const cxtwo = cxs(style)
  t.is(cx, `cxs-${hashname}`)
  t.is(cx, cxtwo) // Double-double checking
})

test('attaches a style tag and CSSStyleSheet', async t => {
  t.plan(1)
  cxs.attach()
  const getTag = () => {
    return new Promise((resolve, reject) => {
      setTimeout(() => {
        const tag = document.getElementById(styleId)
        resolve(tag.tagName)
      }, 200)
    })
  }
  // Travis error with CSSStyleSheet is undefined
  // t.true(cxs.sheet instanceof CSSStyleSheet)
  t.is(await getTag(), 'STYLE')
})

test('Adds px unit to number values', t => {
  const sx = {
    fontSize: 32
  }
  cxs(sx)
  const rules = cxs.rules
  t.regex(rules[0].css, /font-size:32px}$/)
})

test('creates pseudoclass rules', t => {
  t.plan(2)
{'fraction_non_alphanumeric': 0.16779239246356203, 'fraction_numerical': 0.01173124777817277, 'mean_word_length': 3.4106583072100314, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 29, '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': '1814867', 'n_tokens_mistral': 1060, 'n_tokens_neox': 1032, 'n_words': 255}