const blocks = require('..')
const path = require('path')
const test = require('ava')
const vm = require('vm')

blocks.fromFileSync(path.join(__dirname, 'meta.spec.md'))
  .filter(block => (
    block.lang === 'js' && !block.info.skip
  ))
  .map(block => {
    test(block.title, t => {
      const script = new vm.Script(block.value, {
        filename: block.source.file,
        lineOffset: block.source.line,
        displayErrors: true,
      })
      const context = vm.createContext({
        __dirname,
        block,
        blocks,
        test: t,
      })
      const result = script.runInContext(context)
      if (result instanceof Promise) {
        return result
          .then(msg => t.pass(msg))
          .catch(error => t.fail(error))
      } else {
        return t.pass(result)
      }
    })
  })

@@ -105,16 +105,123 @@
 ('vm')%0A%0A
+const tests = %5B'../README.md', 'meta.spec.md'%5D%0A  .reduce((tests, file) =%3E %7B%0A    return tests.concat(%0A      
 blocks.f
@@ -257,23 +257,28 @@
 me, 
-'meta.spec.md')
+file))%0A    )%0A  %7D, %5B%5D
 )%0A  
@@ -322,16 +322,20 @@
  'js' &&
+%0A   
  !block.
@@ -343,16 +343,56 @@
 nfo.skip
+ &&%0A    block.value.indexOf('test') %3E -1
 %0A  ))%0A  

test README.md, too