def tearDown(self): with cd('./tests/root_for_testing'): self.call("rm", "-f", "bsconfig.json") self.call("rm", "-f", ".merlin") self.call("rm", "-rf", "lib") self.call("rm", "-f", "node_modules/reason-package") self.call("cp", "package.empty_scripts.json", "package.json")
def test_config_was_not_created_when_given_bad_target_no_linking(self): with cd('./tests/root_for_testing'): self.call("node", "../../index.js", "setup", 'some/bad/target', self.name, "--no-linking") existsMerlin = self.exists('.merlin') existsBsconfig = self.exists('bsconfig.json') self.assertFalse(existsMerlin, '.merlin file was created even though we gave a bad target') self.assertFalse(existsBsconfig, 'bsconfig.json file was created even though we gave a bad target')
def test_postinstall_was_correctly_added_to_package_file_with_no_scripts_called_twice(self): with cd('./tests/root_for_testing'): self.call("node", "../../index.js", "setup", self.directory, self.name) self.call("node", "../../index.js", "setup", self.directory, self.name) contents = self.read_json('package.json') self.assertIn('scripts', contents, 'Could not find scripts key in the package.json file') self.assertIn('postinstall', contents['scripts'], 'Could not find postinstall key in the package.json scripts key') postinstall_script = contents['scripts']['postinstall'] self.assertEqual(postinstall_script.count(self.should_exist_once_in_postinstall), 1, 'Found more than one instance of our postinstall script')
def test_postinstall_was_not_created_when_given_bad_target(self): with cd('./tests/root_for_testing'): self.call("cp", "package.other_postinstall.json", "package.json") contents = self.read_json('package.json') postinstall_before = contents['scripts']['postinstall'] self.call("node", "../../index.js", "setup", 'some/bad/target', self.name) contents = self.read_json('package.json') postinstall_after = contents['scripts']['postinstall'] self.assertEqual(postinstall_before, postinstall_after, 'The postinstall script was altered even though we gave bad target')
def test_build_command_was_correctly_added_to_package_file_with_other_script(self): with cd('./tests/root_for_testing'): self.call("cp", "package.other_script.json", "package.json") self.call("node", "../../index.js", "setup", self.directory, self.name) contents = self.read_json('package.json') self.assertIn('scripts', contents, 'Could not find scripts key in the package.json file') self.assertIn('build-reason', contents['scripts'], 'Could not find build-reason key in the package.json scripts key') build_command = contents['scripts']['build-reason'] self.assertEqual(build_command.count(self.should_exist_once_in_build), 1, 'Found more than one instance of our postinstall script')
def test_merlin_was_created(self): with cd('./tests/root_for_testing'): self.call("node", "../../index.js", "setup", self.directory, self.name) exists = os.path.isfile('.merlin') self.assertTrue(exists, '.merlin was never created')
def test_steps_pass_in_source_flag(self): with cd('./tests/root_for_testing'): result = self.call("node", "../../index.js", "setup", self.directory, self.name, "--in-source") self.assertTrue(result, 'Standard --in-source setup call did not pass successfully.')
def test_postinstall_was_not_added_to_package_file_with_no_linking_flag(self): with cd('./tests/root_for_testing'): # This uses our default package.json copy which has a scripts key and no postinstall key self.call("node", "../../index.js", "setup", self.directory, self.name, "--no-linking") contents = self.read_json('package.json') self.assertNotIn('postinstall', contents['scripts'], 'Postinstall was created when it should not have been')
def test_proper_bsconfig_file_generated_with(self): with cd('./tests/root_for_testing'): # This uses our default package.json copy which has a scripts key and no postinstall key self.call("node", "../../index.js", "setup", self.directory, self.name) contents = self.read_file('bsconfig.json') self.assertNotIn('in-source', contents, 'Config file wrongly has `in-source` set to true')