<commit_before>
import test from 'ava'
import hash from 'node-murmurhash'
import jsdom from 'jsdom-global'
import cxs, { cache } from '../src'

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

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

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

test('should not throw', t => {
  t.notThrows(() => {
    const cx = 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('adds the rule to cache', t => {
  t.plan(2)
  const id = `cxs-${hash(JSON.stringify(style), 128)}`
  const cx = cxs(style)
  t.is(typeof cache, 'object')
  t.is(typeof cache[id], 'object')
})

test('handles multiple classes', t => {
  const cx = cxs(style, 'red', 'm1')
  t.regex(cx, /^cxs.+\sred\sm1$/)
})

test('clears cache', t => {
  t.plan(1)
  const cx = cxs(style)
  cxs.clearCache()
  t.deepEqual(cache, ({}))
})

test('attaches a style tag and CSSStyleSheet', t => {
  t.plan(2)
  cxs.attach()
  const tag = document.getElementById('cxs')
  t.true(cxs.sheet instanceof CSSStyleSheet)
  t.true(tag.tagName === 'STYLE')
})

test('dedupes repeated styles', t => {
  const dupe = {
    color: 'cyan',
    fontSize: 32
  }
  const cx1 = cxs(style)
  const cx2 = cxs(dupe)
  const cx3 = cxs(dupe)<commit_msg>Add test for style tag<commit_after>
import test from 'ava'
import hash from 'node-murmurhash'
import jsdom from 'jsdom-global'
import cxs, { cache } from '../src'

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

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

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

test('should not throw', t => {
  t.notThrows(() => {
    const cx = 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('adds the rule to cache', t => {
  t.plan(2)
  const id = `cxs-${hash(JSON.stringify(style), 128)}`
  const cx = cxs(style)
  t.is(typeof cache, 'object')
  t.is(typeof cache[id], 'object')
})

test('handles multiple classes', t => {
  const cx = cxs(style, 'red', 'm1')
  t.regex(cx, /^cxs.+\sred\sm1$/)
})

test('attaches a style tag', t => {
  t.plan(2)
  const tag = document.getElementById('cxs')
  t.true(cxs.sheet instanceof CSSStyleSheet)
  t.is(tag.tagName, 'STYLE')
})

test('clears cache', t => {
  t.plan(1)
  const cx = cxs(style)
  cxs.clearCache()
  t.deepEqual(cache, ({}))
})

test('attaches a style tag and CSSStyleSheet', t => {
  t.plan(2)
  cxs.attach()
  const tag = document.getElementById('cxs')
  t.true(cxs.sheet instanceof CSSStyleSheet)
  t.true(tag.tagName === 'STYLE')
})

test('dedupes repeated styles', t => {
  const dupe = {
    color: 'cyan',
    fontSize: 32
  }
  const cx1 = cxs(style)
  const cx2 = cxs(dupe)
  const cx3 = cxs(dupe)
{'fraction_non_alphanumeric': 0.18953185955786736, 'fraction_numerical': 0.012028608582574773, 'mean_word_length': 3.6905487804878048, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 28, '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': '1826460', 'n_tokens_mistral': 1239, 'n_tokens_neox': 1212, 'n_words': 293}